From 92f777e8154f3f8ba3e2bed4d6532acb69722d7b Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Fri, 29 Sep 2017 23:32:29 +0200 Subject: [PATCH] module_utils.urls - Encode the proxy connect as binary (#30811) * module_utils.urls - Encode the proxy connect as binary Under Python3 the sendall method expects binary not a string. Prior to this change the below exception was being thrown; Traceback (most recent call last): File "/tmp/ansible_umxox7_x/ansible_modlib.zip/ansible/module_utils/urls.py", line 1044, in fetch_url client_key=client_key, cookies=cookies) File "/tmp/ansible_umxox7_x/ansible_modlib.zip/ansible/module_utils/urls.py", line 951, in open_url r = urllib_request.urlopen(*urlopen_args) File "/opt/blue-python/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen return opener.open(url, data, timeout) File "/opt/blue-python/3.6/lib/python3.6/urllib/request.py", line 524, in open req = meth(req) File "/tmp/ansible_umxox7_x/ansible_modlib.zip/ansible/module_utils/urls.py", line 729, in http_request s.sendall((self.CONNECT_COMMAND % (self.hostname, self.port)).decode()) AttributeError: 'str' object has no attribute 'decode' Encoding the value is inline with the lines below (Proxy-Authorization etc) which are being sent as binary. --- lib/ansible/module_utils/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index d2f37516ba2..c4d35060b22 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -728,7 +728,7 @@ class SSLValidationHandler(urllib_request.BaseHandler): port = proxy_parts.get('port') or 443 s = socket.create_connection((proxy_parts.get('hostname'), port)) if proxy_parts.get('scheme') == 'http': - s.sendall(self.CONNECT_COMMAND % (self.hostname, self.port)) + s.sendall(to_bytes(self.CONNECT_COMMAND % (self.hostname, self.port), errors='surrogate_or_strict')) if proxy_parts.get('username'): credentials = "%s:%s" % (proxy_parts.get('username', ''), proxy_parts.get('password', '')) s.sendall(b'Proxy-Authorization: Basic %s\r\n' % base64.b64encode(to_bytes(credentials, errors='surrogate_or_strict')).strip())