简体   繁体   中英

Boto3 Error in python2.7 but works in 3.5

So I'm using boto3 to access a s3 service. When I use this code it works fine with python3.5 but throws this exception in 2.7, why? I would like to implement it with 2.7 because my whole project is based on 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:

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. 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? 104 errors can have a variety of sources, including networking and server-side temporary issues.
  • Are you using a stable version of boto3 ? Try using the latest stable version ( 1.4.4 as I'm writing this)
  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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