I've followed all the instructions for installing and enabling django-storages and boto in my app to upload files to S3. (As this application is intended for deployment on Heroku, I'm using virtualenv to manage dependencies.)
For local development I've put all my credentials in ~/.bash_profile:
export AWS_ACCESS_KEY_ID=xxxx
export AWS_SECRET_ACCESS_KEY=yyyy
export S3_BUCKET_NAME=zzzz
So, great, but then this:
> python manage.py shell
>>> import boto
>>> conn = boto.connect_s3()
>>> conn.get_all_buckets()
Produces these debugging messages and this error:
2012-06-04 23:17:34,432 [DEBUG] boto: path=/
2012-06-04 23:17:34,432 [DEBUG] boto: auth_path=/
2012-06-04 23:17:34,433 [DEBUG] boto: Method: GET
2012-06-04 23:17:34,433 [DEBUG] boto: Path: /
2012-06-04 23:17:34,433 [DEBUG] boto: Data:
2012-06-04 23:17:34,433 [DEBUG] boto: Headers: {}
2012-06-04 23:17:34,433 [DEBUG] boto: Host: s3.amazonaws.com
2012-06-04 23:17:34,433 [DEBUG] boto: establishing HTTPS connection: host=s3.amazonaws.com, kwargs={'timeout': 2}
2012-06-04 23:17:34,433 [DEBUG] boto: Token: None
2012-06-04 23:17:34,436 [DEBUG] boto: StringToSign:
GET
Tue, 05 Jun 2012 03:17:34 GMT
2012-06-04 23:17:36,900 [DEBUG] boto: encountered SSLError exception, reconnecting
2012-06-04 23:17:36,901 [DEBUG] boto: establishing HTTPS connection: host=s3.amazonaws.com, kwargs={'timeout': 2}
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "../venv/lib/python2.7/site-packages/boto/s3/connection.py", line 346, in get_all_buckets
response = self.make_request('GET', headers=headers)
File "../venv/lib/python2.7/site-packages/boto/s3/connection.py", line 454, in make_request
override_num_retries=override_num_retries)
File "../venv/lib/python2.7/site-packages/boto/connection.py", line 838, in make_request
return self._mexe(http_request, sender, override_num_retries)
File "../venv/lib/python2.7/site-packages/boto/connection.py", line 803, in _mexe
raise e
SSLError: _ssl.c:484: The handshake operation timed out
What I can't understand is that using the SAME EXACT CREDENTIALS I am able to connect without any problems using a GUI on my Mac to browse S3. I can list all the buckets. I can get into bucket zzzz. I can upload a file to it. I can download it again. I can delete it. All is well. But no matter what I try through Boto it times out with no further comment.
Why is boto timing out in my local environment?
I was able to narrow down the below to:
>>> import httplib
>>> h1 = httplib.HTTPSConnection('s3.amazonaws.com')
>>> h1.request ("GET", "/")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 958, in request
self._send_request(method, url, body, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 992, in _send_request
self.endheaders(body)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 776, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1161, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 382, in wrap_socket
ciphers=ciphers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 143, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 306, in do_handshake
self._sslobj.do_handshake()
error: [Errno 60] Operation timed out
Whereas:
>>> h1 = httplib.HTTPSConnection('google.com')
>>> h1.request ("GET", "/")
>>> r1 = h1.getresponse()
>>> print r1.status, r1.reason
301 Moved Permanently
What is it about AWS that is freaking httplib.HTTPSConnection out?
(I know the request above isn't a correct and complete AWS request, but I simplified it just to try to get a response from the server.)
Unfortunately it seems that the problem is with my home internet! When I took my laptop elsewhere to work, the problem did not repeat itself. So the problem has nothing to do with Django, Boto, AWS, S3, SSL, Python, or anything remotely interesting, and everything to do with how much Time Warner Cable sucks. Can you believe it?!