URL encoding/decoding with Python
url encoding a “raw” unicode doesn’t really make sense. What you need to do is .encode(“utf8″) first so you have a known byte encoding and then .quote() that. The output isn’t very pretty but it should be a correct uri encoding. >>> s = u’1234567890-/:;()$&@”.,?!\'[]{}#%^*+=_\|~<>\u20ac\xa3\xa5\u2022.,?!\” >>> urllib2.quote(s.encode(“utf8”)) ‘1234567890-/%3A%3B%28%29%24%26%40%22.%2C%3F%21%27%5B%5D%7B%7D%23%25%5E%2A%2B%3D_%5C%7C%7E%3C%3E%E2%82%AC%C2%A3%C2%A5%E2%80%A2.%2C%3F%21%27’ Remember that you will need to both … Read more