]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix Issue8123 - TypeError in urllib when trying to use HTTP authentication
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 1 Aug 2010 17:53:37 +0000 (17:53 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 1 Aug 2010 17:53:37 +0000 (17:53 +0000)
Lib/test/test_urllib.py
Lib/urllib/request.py

index cea153e907a6330afa0e7d30d326605ceb95979e..98308b6af1c5c15bb707b10a33a39ca7b730108d 100644 (file)
@@ -190,6 +190,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 6c4b5f7cae566e5fe19e5b66b856c9ccb37bea12..24a4797c884d05e431e11411649126e3cdb6b8e8 100644 (file)
@@ -1591,13 +1591,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)