urllib2: problem of handling space in parameter

M

Muddy Coder

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!

Muddy Coder
 
R

rdmurray

Quoth Muddy Coder said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top