Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47956
| Date | 2013-06-13 16:05 +0300 |
|---|---|
| Subject | Must we include urllib just to decode a URL-encoded string, when using Requests? |
| From | Dotan Cohen <dotancohen@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3188.1371128728.3114.python-list@python.org> (permalink) |
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
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Must we include urllib just to decode a URL-encoded string, when using Requests? Dotan Cohen <dotancohen@gmail.com> - 2013-06-13 16:05 +0300
csiph-web