Must we include urllib just to decode a URL-encoded string, whenusing Requests?

D

Dotan Cohen

I am using the Requests module to access remote URLs. Sometimes I need
to URL-decode or URL-encode a string (via RFC 3986). Must I import
urllib or urllib2 just to use their quote() and unquote() methods?
Does not Requests have such an ability, and perhaps I just cannot find
it?

On Stack Overflow [1] I found this wonderful function:
def unquote(url):
return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m:
chr(int(m.group(1),16)), url)

I am already importing the 're' module so that is not an issue. I am
concerned, though, that this might not work for some non-ASCII
characters such as some esoteric symbols or Korean/Chinese/Japanese
characters.

[1] http://stackoverflow.com/a/15627281/343302
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,729
Latest member
ScarlettJe

Latest Threads

Top