urllib question

Matthew Schinckel matt at null.net
Mon Jun 19 20:10:48 EDT 2000


paul at fizzylab.com wrote:
> Why does the first example work, but not the second (actual URL not
> supplied, but you get the idea)?
> 
> I assume something to do with query string values and encoding: even
> if I was right, I have been unsuccessful at making it work.
> 
> #!/usr/bin/python import string, urllib
> 
> u = urllib.urlopen(string.join(["http://cnn.com/", "index.html"]))
> print u.read() u =
> urllib.urlopen(string.join(["http://some.host.com/",
> "montstrousQueryString?withParameters"])) print u.read()
> 
> My second day trying to use python . . . excuse my thickness of skull.

I would suggest using urlparse.urljoin(), it then makes sure it is a
valid URL, and you can also urllib.urlencode() a dictionary of values
rather than get a string.

Matt.



More information about the Python-list mailing list