我正在编写一个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 one和this one,说〜/ .aws / config中的config address_style = path可以正常工作。我试过但失败了。