mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix Issue8123 - TypeError in urllib when trying to use HTTP authentication
This commit is contained in:
parent
c881f1592f
commit
de0eb249c6
2 changed files with 13 additions and 2 deletions
|
@ -190,6 +190,17 @@ Content-Type: text/html; charset=iso-8859-1
|
||||||
finally:
|
finally:
|
||||||
self.unfakehttp()
|
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):
|
class urlretrieve_FileTests(unittest.TestCase):
|
||||||
"""Test urllib.urlretrieve() on local files"""
|
"""Test urllib.urlretrieve() on local files"""
|
||||||
|
|
||||||
|
|
|
@ -1591,13 +1591,13 @@ class URLopener:
|
||||||
|
|
||||||
if proxy_passwd:
|
if proxy_passwd:
|
||||||
import base64
|
import base64
|
||||||
proxy_auth = base64.b64encode(proxy_passwd).strip()
|
proxy_auth = base64.b64encode(proxy_passwd.encode()).strip()
|
||||||
else:
|
else:
|
||||||
proxy_auth = None
|
proxy_auth = None
|
||||||
|
|
||||||
if user_passwd:
|
if user_passwd:
|
||||||
import base64
|
import base64
|
||||||
auth = base64.b64encode(user_passwd).strip()
|
auth = base64.b64encode(user_passwd.encode()).strip()
|
||||||
else:
|
else:
|
||||||
auth = None
|
auth = None
|
||||||
http_conn = connection_factory(host)
|
http_conn = connection_factory(host)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue