无法连接桶使用博托AWS S3 [英] Unable to connect aws s3 bucket using boto

查看:205
本文介绍了无法连接桶使用博托AWS S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AWS_ACCESS_KEY_ID = '<access key>'
AWS_SECRET_ACCESS_KEY = '<my secret key>'
Bucketname = 'Bucket-name' 
import boto
from boto.s3.key import Key
import boto.s3.connection
conn = boto.connect_s3(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,
        host ='s3.ap-southeast-1.amazonaws.com',
        is_secure=True,               # uncommmnt if you are not using ssl
        calling_format = boto.s3.connection.OrdinaryCallingFormat(),
        )
bucket = conn.get_bucket(Bucketname)

错误:

  Traceback (most recent call last):
   File "uploads3.py", line 69, in <module>
    upload_hello_file_s3()
  File "uploads3.py", line 25, in upload_hello_file_s3
    bucket = conn.get_bucket(Bucketname)
  File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 431, in get_bucket
    bucket.get_all_keys(headers, maxkeys=0)
  File "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 364, in get_all_keys
    '', headers, **params)
  File "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 321, in _get_all
    query_args=s)
  File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 543, in make_request
    override_num_retries=override_num_retries)
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 937, in make_request
    return self._mexe(http_request, sender, override_num_retries)
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 899, in _mexe
    raise e
socket.gaierror: [Errno -2] Name or service not known

请帮我解决这个问题有斗名和访问密钥和秘密密钥没有问题。

please help me to solve this problem there is no problem in bucket name and access key and secret key.

推荐答案

您也可以使用以下(boto.s3.connect_to_region):

You can also use the following (boto.s3.connect_to_region):

import boto
from boto.s3.key import Key
import boto.s3.connection

AWS_ACCESS_KEY_ID = '<access key>'
AWS_SECRET_ACCESS_KEY = '<my secret key>'
Bucketname = 'Bucket-name' 


conn = boto.s3.connect_to_region('ap-southeast-1',
       aws_access_key_id=AWS_ACCESS_KEY_ID,
       aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
       is_secure=True,               # uncommmnt if you are not using ssl
       calling_format = boto.s3.connection.OrdinaryCallingFormat(),
       )
bucket = conn.get_bucket(Bucketname)

这样,您就不必关心确切的端点。是的像@garnaat提到的,使用最新的博托API。

This way you don't have to care about the exact endpoint. And yes like @garnaat mentioned, use the latest boto API.

这篇关于无法连接桶使用博托AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆