boto / boto

For the latest version of boto, see https://github.com/boto/boto3 -- Python interface to Amazon Web Services
http://docs.pythonboto.org/
Other
6.48k stars 2.26k forks source link

Python3: route53 module fails to connect with error "TypeError: a bytes-like object is required, not 'str'" #3837

Open ps-jay opened 6 years ago

ps-jay commented 6 years ago
SUMMARY

When using the route53 module (as included by Ansible) on Python3 with:

... and I have proxies defined, then I experience a traceback TypeError: a bytes-like object is required, not 'str'.

DETAIL

I have reported this in Ansible issue #44613, and it has been determined that this is a boto issue.

The stack trace is from the Ansible run, but it should be illustrative of the issue in boto:

<localhost> EXEC /bin/sh -c 'HTTP_PROXY=http://forwardproxy:3128 HTTPS_PROXY=http://forwardproxy:3128 http_proxy=http://forwardproxy:3128 https_proxy=http://forwardproxy:3128 NO_PROXY=169.254.169.254,127.0.0.1,localhost no_proxy=169.254.169.254,127.0.0.1,localhost /usr/local/bin/python /home/appuser/.ansible/tmp/ansible-tmp-1535074534.0887613-42832137475137/route53.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/appuser/.ansible/tmp/ansible-tmp-1535074534.0887613-42832137475137/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_lo1nb17k/ansible_module_route53.py", line 674, in <module>
    main()
  File "/tmp/ansible_lo1nb17k/ansible_module_route53.py", line 557, in main
    zone = get_zone_by_name(conn, module, zone_in, private_zone_in, hosted_zone_id_in, vpc_id_in)
  File "/tmp/ansible_lo1nb17k/ansible_module_route53.py", line 388, in get_zone_by_name
    for zone in invoke_with_throttling_retries(conn.get_zones):
  File "/tmp/ansible_lo1nb17k/ansible_module_route53.py", line 448, in invoke_with_throttling_retries
    retval = function_ref(*argv, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/boto/route53/connection.py", line 559, in get_zones
    zones = self.get_all_hosted_zones()
  File "/usr/local/lib/python3.7/site-packages/boto/route53/connection.py", line 120, in get_all_hosted_zones
    params=params)
  File "/usr/local/lib/python3.7/site-packages/boto/route53/connection.py", line 103, in make_request
    retry_handler=self._retry_handler)
  File "/usr/local/lib/python3.7/site-packages/boto/connection.py", line 1071, in make_request
    retry_handler=retry_handler)
  File "/usr/local/lib/python3.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/usr/local/lib/python3.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/usr/local/lib/python3.7/site-packages/boto/connection.py", line 747, in new_http_connection
    connection = self.proxy_ssl(host, is_secure and 443 or 80)
  File "/usr/local/lib/python3.7/site-packages/boto/connection.py", line 796, in proxy_ssl
    sock.sendall("CONNECT %s HTTP/1.0\r\n" % host)
TypeError: a bytes-like object is required, not 'str'

Eventually we hit the issue when setting the proxy here:

  File "/usr/local/lib/python3.7/site-packages/boto/connection.py", line 796, in proxy_ssl
    sock.sendall("CONNECT %s HTTP/1.0\r\n" % host)
TypeError: a bytes-like object is required, not 'str'

Route53 is marked as Python3 compatible, but I understand that using proxies would be an edge-case not necessarily tested for.

ps-jay commented 6 years ago

Also, this is a problem in S3, as reported here: #3561

ps-jay commented 6 years ago

Actually, here is the fix: https://github.com/boto/boto/pull/3699 It just needs to be merged.

rmehra7 commented 3 years ago

@ansibot Is there any commuity module available for ec2_vol? Getting same error for ec2_vol - TypeError: a bytes-like object is required, not 'str'