Correct URL encoding

Chris Rebert clp2 at rebertia.com
Sun Mar 15 20:05:16 EDT 2009


On Sun, Mar 15, 2009 at 4:54 PM, gervaz <gervaz at gmail.com> wrote:
> On Mar 16, 12:38 am, Graham Breed <x3... at cnntp.org> wrote:
>> mattia wrote:
>> > I'm using urlopen in order to download some web pages. I've always to
>> > replace some characters that are in the url, so I've come up with:
>> > url.replace("|", "%7C").replace("/", "%2F").replace(" ", "+").replace
>> > (":", "%3A")
>> > There isn't a better way of doing this?
>>
>> Yeah, shame there's no function -- called "urlencode" say --
>> that does it all for you.
>>
>>                        Graham
>
> Sorry, but using Python 2.6 and urlencode I've got this error:
> TypeError: not a valid non-string sequence or mapping object
> What I was looking for (found in Python3) is:
> from urllib.parse import quote
> urlopen(quote(url)).read()
> but seems there is nothing similar in py2.6

(*cough*) [Python v2.6.1 documentation] urllib.quote() -
http://docs.python.org/library/urllib.html#urllib.quote (*cough*)

- Chris

-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list