diff options
-rw-r--r-- | Lib/test/test_urllib.py | 11 | ||||
-rw-r--r-- | Lib/urllib/request.py | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index acd5577..c573f14 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -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""" diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 14ea0aa..4522466 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -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) |