简体   繁体   English

python2.7中的Boto3错误,但在3.5版中有效

[英]Boto3 Error in python2.7 but works in 3.5

So I'm using boto3 to access a s3 service. 因此,我正在使用boto3访问s3服务。 When I use this code it works fine with python3.5 but throws this exception in 2.7, why? 当我使用此代码时,它可以在python3.5上正常工作,但在2.7中抛出此异常,为什么? I would like to implement it with 2.7 because my whole project is based on 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")

With 2.7 this exception is thrown: 在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'))

Looking at the error message it doesn't seem to be an issue related specifically to the python version, as Boto3 supports Python 2.7 out of the box. 查看错误消息,似乎并不是专门针对python版本的问题,因为Boto3开箱即用地支持Python 2.7。 So I made a quick checklist that may (or not) help you find the cause of your problem 因此,我做了一个快速检查清单,该清单可能会(或不会)帮助您找到问题的原因

  • Have you tried both versions of Python under the same environment? 您是否在同一环境下尝试过这两个版本的Python? 104 errors can have a variety of sources, including networking and server-side temporary issues. 104错误可能来自多种原因,包括网络和服务器端临时问题。
  • Are you using a stable version of boto3 ? 您是否正在使用boto3的稳定版本? Try using the latest stable version ( 1.4.4 as I'm writing this) 尝试使用最新的稳定版本(在撰写本文时为1.4.4
  • If the previous doesn't work, try using a previous stable version. 如果以前的版本不起作用,请尝试使用以前的稳定版本。 Some times these bugs with legacy environments are introduced with newer releases. 有时,旧版本中的这些错误是在较新版本中引入的。
  • If none of it works, try filing a bug. 如果所有方法均无效,请尝试提交错误。 The boto team is partially supported by Amazon and responds quite quickly to app-breaking issues. Boto团队得到了Amazon的部分支持,并且对应用程序中断问题做出了快速响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM