urllib2: problem of handling space in parameter

rdmurray at bitdance.com rdmurray at bitdance.com
Sat Feb 7 09:16:42 EST 2009


Quoth Muddy Coder <cosmo_general at yahoo.com>:
> Hi Folks,
> 
> I encrountered a problem of using urllib2: the space handling. Look at
> the code below:
> 
> import urllib2
> url = r'http://somedomain.com/a.cgi?name=muddy coder&password=foobar
> cgi_back = urllib2.urlopen(url).read()
> 
> In this cgi_back, I saw field password worked fine, but field name
> not, only muddy was picked up by CGI. So, I had to cover the space, by
> using syntax name=muddy-coder, it went through. So, I presume urllib2
> may have an approach of handling white space in this regard. Can
> anybody help? Thanks!

urllib.urlencode.  Unecoded spaces aren't actually valid in a URL.

--David




More information about the Python-list mailing list