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.
This commit is contained in:
parent
43cbcbcc75
commit
92f777e815
1 changed files with 1 additions and 1 deletions
|
@ -728,7 +728,7 @@ class SSLValidationHandler(urllib_request.BaseHandler):
|
||||||
port = proxy_parts.get('port') or 443
|
port = proxy_parts.get('port') or 443
|
||||||
s = socket.create_connection((proxy_parts.get('hostname'), port))
|
s = socket.create_connection((proxy_parts.get('hostname'), port))
|
||||||
if proxy_parts.get('scheme') == 'http':
|
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'):
|
if proxy_parts.get('username'):
|
||||||
credentials = "%s:%s" % (proxy_parts.get('username', ''), proxy_parts.get('password', ''))
|
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())
|
s.sendall(b'Proxy-Authorization: Basic %s\r\n' % base64.b64encode(to_bytes(credentials, errors='surrogate_or_strict')).strip())
|
||||||
|
|
Loading…
Reference in a new issue