diff -r 66f2bcb47050 Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Thu Jan 12 08:09:15 2012 +0100 +++ b/Lib/test/test_urllib2.py Thu Jan 12 16:22:44 2012 +0100 @@ -6,7 +6,7 @@ import StringIO import urllib2 -from urllib2 import Request, OpenerDirector +from urllib2 import Request, OpenerDirector, quote # XXX # Request @@ -1281,6 +1281,16 @@ 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()) + + 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 = urllib2.Request("http://www.python.org/") diff -r 66f2bcb47050 Lib/urllib2.py --- a/Lib/urllib2.py Thu Jan 12 08:09:15 2012 +0100 +++ b/Lib/urllib2.py Thu Jan 12 16:22:44 2012 +0100 @@ -195,7 +195,10 @@ def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False): # unwrap('') --> 'type://host/path' - self.__original = unwrap(url) + # percent encode url, fixing lame server errors for e.g, + # like space within url paths. + self.__original = quote(unwrap(url), + safe="%/:=&?~#+!$,;'@()*[]|") self.__original, self.__fragment = splittag(self.__original) self.type = None # self.__r_type is what's left after doing the splittype