]> granicus.if.org Git - python/commitdiff
Merged revisions 83415 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 1 Aug 2010 17:55:50 +0000 (17:55 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 1 Aug 2010 17:55:50 +0000 (17:55 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r83415 | senthil.kumaran | 2010-08-01 23:23:37 +0530 (Sun, 01 Aug 2010) | 3 lines

  Fix Issue8123 - TypeError in urllib when trying to use HTTP authentication
........

Lib/test/test_urllib.py
Lib/urllib/request.py

index acd55778248c6f91726db4655e483a65ae500151..c573f147f14cd2786ca22a65a5cac719bc298882 100644 (file)
@@ -191,6 +191,17 @@ Content-Type: text/html; charset=iso-8859-1
         finally:
             self.unfakehttp()
 
+    def test_userpass_inurl(self):
+        self.fakehttp(b"Hello!")
+        try:
+            fp = urlopen("http://user:pass@python.org/")
+            self.assertEqual(fp.readline(), b"Hello!")
+            self.assertEqual(fp.readline(), b"")
+            self.assertEqual(fp.geturl(), 'http://user:pass@python.org/')
+            self.assertEqual(fp.getcode(), 200)
+        finally:
+            self.unfakehttp()
+
 class urlretrieve_FileTests(unittest.TestCase):
     """Test urllib.urlretrieve() on local files"""
 
index 14ea0aad5ed6d32dfdd4ebbbd4dc5aa960ca8191..4522466722e72820da39a5256bc228439fab41f0 100644 (file)
@@ -1595,13 +1595,13 @@ class URLopener:
 
         if proxy_passwd:
             import base64
-            proxy_auth = base64.b64encode(proxy_passwd).strip()
+            proxy_auth = base64.b64encode(proxy_passwd.encode()).strip()
         else:
             proxy_auth = None
 
         if user_passwd:
             import base64
-            auth = base64.b64encode(user_passwd).strip()
+            auth = base64.b64encode(user_passwd.encode()).strip()
         else:
             auth = None
         http_conn = connection_factory(host)