python2.7中的Boto3错误但在3.5

时间:2017-06-21 11:56:13

标签: python python-2.7 amazon-s3 python-3.5 boto3

所以我使用boto3来访问s3服务。当我使用这段代码时,它可以正常使用python3.5但在2.7中抛出此异常,为什么?我想用2.7实现它,因为我的整个项目基于2.7。

import boto3

conn = boto3.resource('s3', region_name='eu-west-1', endpoint_url=HOST, aws_access_key_id=KEY, aws_secret_access_key=SECRET)

conn.create_bucket(Bucket="pqlamy194762123")

使用2.7抛出此异常:

Traceback (most recent call last):
  File "s3connector.py", line 22, in <module>
    s.createBucket('pqlamy1947621234')
  File "s3connector.py", line 15, in createBucket
    self.s3.create_bucket(Bucket=name ,CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'})
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/client.py", line 310, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/client.py", line 586, in _make_api_call
    operation_model, request_dict)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 141, in make_request
    return self._send_request(request_dict, operation_model)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 170, in _send_request
    success_response, exception):
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 249, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/retryhandler.py", line 277, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/retryhandler.py", line 317, in __call__
    caught_exception)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/home/elk/.local/lib/python2.7/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
botocore.vendored.requests.exceptions.ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))

1 个答案:

答案 0 :(得分:0)

查看错误消息它似乎不是一个与python版本相关的问题,因为Boto3支持开箱即用的Python 2.7。因此,我制作了一份快速清单,可能(或不)帮助您找到问题的原因

  • 您是否在同一环境下尝试过两种版本的Python? 104错误可能有多种来源,包括网络和服务器端临时问题。
  • 您使用的是boto3的稳定版本吗?尝试使用最新的稳定版本(1.4.4,因为我写这篇文章)
  • 如果之前的版本不起作用,请尝试使用以前的稳定版本。有些时候,旧版本中会出现这些带有旧版本的错误。
  • 如果没有,请尝试提交错误。亚马逊部分支持boto团队,并对应用程序破解问题做出快速响应。