当桶名称具有句点时,boto3将文件上传到s3错误

时间:2016-01-22 08:55:21

标签: amazon-web-services amazon-s3 boto3

我正在编写一个python脚本,用boto3将文件上传到s3。我的桶名称就像'my.bucket',我得到连接超时错误。

这是错误代码。

    botocore.vendored.requests.exceptions.ConnectTimeout:        
    HTTPSConnectionPool(host='s3-ap-northeast-1.amazonaws.com', port=443):      
    Max retries exceeded with url: /pandarental.com/app.css (Caused by 
    ConnectTimeoutError(<botocore.awsrequest.AWSHTTPSConnection object at 
    0x108ff6350>, 'Connection to s3-ap-northeast-1.amazonaws.com timed out.         
    (connect timeout=60)'))

我尝试将存储桶名称更改为“mybucket”并且有效! 我不知道它有什么问题,boto3不支持带有句点的桶名吗?

这是我的代码:

    class StorageManage():
    def __init__(self, bucket_name):
      s3 = boto3.resource('s3')
      self.bucket = s3.Bucket(bucket_name)

    def putObject(self, file_name, key, type):
      try:
        t = content_type.get(type,{})
        with open(file_name, 'rb') as data:
            new_object = self.bucket.put_object(Key=key, Body=data, 
                ACL=t.get('ACL',''), 
                ContentType=t.get('ContentType',''), 
                CacheControl=t.get('CacheControl',''),
                ContentEncoding=t.get('ContentEncoding',''))

        print 'upload file %s success' % new_object.key 
    except botocore.exceptions.ClientError as e:
        print e
    return None

顺便说一下,我发现了两个问题:this onethis one,说〜/ .aws / config中的config address_style = path可以正常工作。我试过但失败了。

0 个答案:

没有答案