When I was making a Python script using the boto library to play with AWS, I made a note of it because it fit under the Proxy environment. Please note that it is close to bad know-how, which is not a best practice.
・ Linux (RHEL6.5) ・ Python 3.3.6 -AWS SDK for Python (boto2.34.0) ・ Under HTTP Proxy environment
If you use Proxy, you will get the following error when calling API.
# python3
>>> import boto.ec2
>>> conn = boto.ec2.connect_to_region(‘ap-northeast-1’)
>>> conn.get_only_instances(instance_ids=[‘i-0de8dc14’])
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/ec2/connection.py”, line 623, in get_only_instances
next_token=next_token)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/ec2/connection.py”, line 682, in get_all_reservations
[(‘item’, Reservation)], verb=‘POST’)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/connection.py”, line 1166, in get_list
response = self.make_request(action, params, path, verb)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/connection.py”, line 1112, in make_request
return self._mexe(http_request)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/connection.py”, line 913, in _mexe
self.is_secure)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/connection.py”, line 705, in get_http_connection
return self.new_http_connection(host, port, is_secure)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/connection.py”, line 747, in new_http_connection
connection = self.proxy_ssl(host, is_secure and 443 or 80)
File “/opt/python3.3.6/lib/python3.3/site-packages/boto/connection.py”, line 796, in proxy_ssl
sock.sendall(“CONNECT %s HTTP/1.0\r\n” % host)
TypeError: ‘str’ does not support the buffer interface
It looks like SSL communication wasn't going through well, so When making a connection, I was able to connect by adding ʻis_secure = False`. However, as the setting value name suggests, it is likely to be non-SSL communication, so you should be careful about the usage scene.
>>> conn = boto.ec2.connect_to_region(‘ap-northeast-1’,is_secure=False)
>>> conn.get_only_instances(instance_ids=[‘i-0de8dc14’])
>>> [Instance:i-0de8dc14]
It seems that the boto library can be loaded with some settings at runtime.
/etc/boto.cfg
- for site-wide settings that all users on this machine > will use~/.boto
- for user-specific settings~/.aws/credentials
- for credentials shared between SDKs
Regarding Proxy, it seems good to describe as follows.
~/.boto
[Boto]
proxy = myproxy.com
proxy_port = 8080
However, in my environment, this did not seem to be able to be read well for some reason, so I came up with hard coding as a temporary measure. If you have any know-how in this area, please comment.
Recommended Posts