Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47956 > unrolled thread
| Started by | Dotan Cohen <dotancohen@gmail.com> |
|---|---|
| First post | 2013-06-13 16:05 +0300 |
| Last post | 2013-06-13 16:05 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
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
| From | Dotan Cohen <dotancohen@gmail.com> |
|---|---|
| Date | 2013-06-13 16:05 +0300 |
| Subject | Must we include urllib just to decode a URL-encoded string, when using Requests? |
| Message-ID | <mailman.3188.1371128728.3114.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web