diff -r 43d08528223c Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Thu Jan 12 08:06:49 2012 +0100 +++ b/Lib/test/test_urllib2.py Thu Jan 12 16:02:37 2012 +0100 @@ -10,7 +10,8 @@ import urllib.request # The proxy bypass method imported below has logic specific to the OSX # proxy config data structure but is testable on all platforms. -from urllib.request import Request, OpenerDirector, _proxy_bypass_macosx_sysconf +from urllib.request import _proxy_bypass_macosx_sysconf +from urllib.request import Request, OpenerDirector, quote import urllib.error # XXX @@ -1425,6 +1426,11 @@ self.assertEqual("http://www.python.org/~jeremy/", self.get.get_full_url()) + url_with_spaces = "http://www.python.org/url with/ a lot of spaces/" + req = Request(url_with_spaces) + self.assertEqual(quote(url_with_spaces, safe="%/:=&?~#+!$,;'@()*[]|"), + req.get_full_url()) + def test_selector(self): self.assertEqual("/~jeremy/", self.get.get_selector()) req = Request("http://www.python.org/") diff -r 43d08528223c Lib/urllib/request.py --- a/Lib/urllib/request.py Thu Jan 12 08:06:49 2012 +0100 +++ b/Lib/urllib/request.py Thu Jan 12 16:02:37 2012 +0100 @@ -195,7 +195,9 @@ origin_req_host=None, unverifiable=False, method=None): # unwrap('') --> 'type://host/path' - self.full_url = unwrap(url) + # percent encode url, fixing lame server errors for e.g, + # like space within url paths. + self.full_url = quote(unwrap(url), safe="%/:=&?~#+!$,;'@()*[]|") self.full_url, self.fragment = splittag(self.full_url) self.data = data self.headers = {}