我已经按照所有说明在我的应用程序中安装并启用django-storages和boto来将文件上传到S3。 (由于此应用程序旨在在Heroku上进行部署,因此我正在使用virtualenv来管理依赖项。)
为了进行本地开发,我将所有凭据都放入〜/ .bash_profile:
export AWS_ACCESS_KEY_ID=xxxx
export AWS_SECRET_ACCESS_KEY=yyyy
export S3_BUCKET_NAME=zzzz
所以,很好,但是这:
> python manage.py shell
>>> import boto
>>> conn = boto.connect_s3()
>>> conn.get_all_buckets()
产生这些调试消息和此错误:
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
我不明白的是,使用完全相同的凭据,我可以使用Mac上的GUI来浏览S3,而不会出现任何问题。我可以列出所有桶。我可以进入水桶zzzz。我可以上传文件。我可以再次下载。我可以删除它。一切都很好。但是,无论我通过Boto尝试什么,它都会超时,无需进一步评论。
为什么Boto在我的本地环境中超时?
我能够将以下范围缩小到:
>>> 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
位置:
>>> h1 = httplib.HTTPSConnection('google.com')
>>> h1.request ("GET", "/")
>>> r1 = h1.getresponse()
>>> print r1.status, r1.reason
301 Moved Permanently
关于使httplib.HTTPSConnection崩溃的AWS是什么?
((我知道上述请求不是正确且完整的AWS请求,但我只是为了尝试从服务器获得响应而简化了该请求。)
基于调试输出中的这一行:
boto: establishing HTTPS connection: host=s3.amazonaws.com, kwargs={'timeout': 2}
我假设您已经在boto配置文件中放入了类似的内容:
[Boto]
http_socket_timeout = 2
正确吗?如果是这样,将超时时间增加到10秒或20秒会发生什么情况。您还超时吗?
不幸的是,问题出在我的家庭互联网上!当我将笔记本电脑带到其他地方工作时,问题并没有重演。因此,该问题与Django,Boto,AWS,S3,SSL,Python或任何其他有趣的问题无关,并且与Time Warner Cable的浪费无关。你相信吗?!