Python 无法在s3中创建存储桶

Python 无法在s3中创建存储桶,python,amazon-s3,Python,Amazon S3,我试图在s3中使用USEast1作为位置 from boto.s3.connection import Location mybucket = 'test-voip1' conn = boto.connect_s3(aws_access_key_id, aws_secret_access_key) if conn.lookup(mybucket) is None: conn.create_bucket(mybucket, location=Location.USEast1)

我试图在s3中使用USEast1作为位置

from boto.s3.connection import Location

mybucket = 'test-voip1'
conn = boto.connect_s3(aws_access_key_id, aws_secret_access_key)
if conn.lookup(mybucket) is None:
     conn.create_bucket(mybucket, location=Location.USEast1)
     # conn.create_bucket(mybucket)
当我尝试运行时,它会给我一个属性错误

Traceback (most recent call last):
   File "s2t_amazon.py", line 146, in <module>
        conn.create_bucket(mybucket, location=Location.USEast1)
AttributeError: type object 'Location' has no attribute 'USEast1'
我也有类似的错误

 botocore.exceptions.ClientError: An error occurred (InvalidLocationConstraint) when calling the CreateBucket operation: The specified location-constraint is not valid
如何解决错误

当我试图检查s3中其他先前创建的bucket的位置时

bucket = conn.get_bucket('ml-vectors')
bucket.get_location()
>> ''

它为空,我无法检查其他bucket是如何在由其他人创建的s3中创建的。

查看AWS connection.py中Location类的定义后,可以理解您遇到的错误:

class Location(object):

DEFAULT = ''  # US Classic Region
EU = 'EU'  # Ireland
EUCentral1 = 'eu-central-1'  # Frankfurt
USWest = 'us-west-1'
USWest2 = 'us-west-2'
SAEast = 'sa-east-1'
APNortheast = 'ap-northeast-1'
APSoutheast = 'ap-southeast-1'
APSoutheast2 = 'ap-southeast-2'
CNNorth1 = 'cn-north-1'
如您所见,这是没有用的。此问题的解决方案可在以下报价中找到:

如所示:“如果您正在美国东部(北弗吉尼亚州)地区(US-East-1)创建桶,则无需指定位置约束”。 其他地区运作良好。我可以接这个

您可以找到以下内容的完整讨论:

您使用的是2还是3?我尝试了这两种方法,但这两种方法都无法创建。我仍然可以使用其他位置创建,但无法使用USEast。即使我只是通过删除位置来使用“conn.create_bucket(bucket_name)”,因为它将选择默认值。
class Location(object):

DEFAULT = ''  # US Classic Region
EU = 'EU'  # Ireland
EUCentral1 = 'eu-central-1'  # Frankfurt
USWest = 'us-west-1'
USWest2 = 'us-west-2'
SAEast = 'sa-east-1'
APNortheast = 'ap-northeast-1'
APSoutheast = 'ap-southeast-1'
APSoutheast2 = 'ap-southeast-2'
CNNorth1 = 'cn-north-1'