Skip to content

Commit c8dcfb6

Browse files
committed
part of #3613: fix get_host_info() usage of base64.encodestring().
1 parent 35e2c4e commit c8dcfb6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Lib/test/test_xmlrpc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ def test_dump_none(self):
135135
xmlrpclib.loads(strg)[0][0])
136136
self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
137137

138+
def test_get_host_info(self):
139+
# see bug #3613, this raised a TypeError
140+
transp = xmlrpc.client.Transport()
141+
self.assertEquals(transp.get_host_info("user@host.tld"),
142+
('host.tld',
143+
[('Authorization', 'Basic dXNlcg==')], {}))
144+
145+
138146
class HelperTestCase(unittest.TestCase):
139147
def test_escape(self):
140148
self.assertEqual(xmlrpclib.escape("a&b"), "a&b")

Lib/xmlrpc/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,8 @@ def get_host_info(self, host):
11611161

11621162
if auth:
11631163
import base64
1164-
auth = base64.encodestring(urllib.parse.unquote(auth))
1164+
auth = urllib.parse.unquote_to_bytes(auth)
1165+
auth = base64.encodestring(auth).decode("utf-8")
11651166
auth = "".join(auth.split()) # get rid of whitespace
11661167
extra_headers = [
11671168
("Authorization", "Basic " + auth)

0 commit comments

Comments
 (0)