4

我已经从 升级了 boto3 boto3==1.7.48 to 1.13.11,这破坏了我所有使用 Moto 的测试。看起来(令人担忧)模拟已经完全停止工作并试图实际访问 s3,这是一个以前工作的示例测试函数:

def upload_video(self, video):
    s3 = boto3.client("s3")
    s3.create_bucket(Bucket=settings.AWS_STORAGE_BUCKET_NAME)
    for media_key in video.upload_media_keys:
        s3.upload_file(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)), "assets/test.mp4"
            ),
            settings.AWS_STORAGE_BUCKET_NAME,
            media_key,
        )

但它现在给出了这个错误

  File "{path}", line 52, in upload_video
    s3.create_bucket(Bucket=settings.AWS_STORAGE_BUCKET_NAME)
  File "{path}/lib/python3.7/site-packages/botocore/client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "{path}/lib/python3.7/site-packages/botocore/client.py", line 635, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.

任何帮助将不胜感激。以下是升级列表:

前:

boto3 == 1.7.48
botocore == 1.10.84
moto == 1.3.6

后:

boto3==1.13.11
botocore==1.16.11 
moto==1.3.14  
4

1 回答 1

7

我不知道发生了什么变化,但我也遇到了这个。这是我的解决方法:

以前我有:

    conn = boto3.resource("s3", region_name="ca-central-1")
    conn.create_bucket(Bucket=os.environ["S3_BUCKET_NAME"]

但是我将区域更改为us-east-1并且一切正常

    conn = boto3.resource("s3", region_name="us-east-1")
    conn.create_bucket(Bucket=os.environ["S3_BUCKET_NAME"]

由于这只是一个用于测试的假存储桶,因此我认为使用不同的区域可以使事情正常进行并没有什么坏处

于 2020-10-26T14:48:18.380 回答