gpt4 book ai didi

python - 调用 PutObject 操作时的 PermanentRedirect

转载 作者:行者123 更新时间:2023-11-28 22:41:53 30 4
gpt4 key购买 nike

下面的代码在本地工作并将文件从目录上传到 S3。它使用 Boto3 和 Python 3。

s3 = boto3.resource('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY_SECRET)
bucket = s3.Bucket(bucket_name)
uploadFileNames = []
for (sourceDir, dirname, filenames) in os.walk(sourceDir):
for filename in filenames:
bucket.put_object(Key=filename, Body=open("{}{}".format(sourceDir, filename), "rb"))
break

我的问题是,当我在生产服务器 (Ubuntu) 上运行相同的代码时,出现以下错误,为什么?

    return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.4/site-packages/botocore/client.py", line 335, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (PermanentRedirect) when calling the PutObject operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

再次在我的 Mac 本地运行此代码,它仅在我的 Ubuntu 服务器上出现此错误。

最佳答案

错误说:

An error occurred (PermanentRedirect) when calling the PutObject operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

当您使用的 Amazon S3 存储桶与创建 Amazon S3 客户端的位置位于不同的区域时,通常会发生这种情况。

例如,存储桶位于 us-west-2,但客户端是为 ap-southeast-2 创建的。

您可以指定区域via a credentials file ,或者在创建客户端对象时传递 region_name。也可以在 boto3.setup_default_session() 中定义默认区域.

关于python - 调用 PutObject 操作时的 PermanentRedirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32246149/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com