调用 PutObject 操作时的 PermanentRedirect
PermanentRedirect when calling the PutObject operation
下面的代码在本地工作并将文件从目录上传到 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, or by passing a region_name
when creating the client object. A default region can also be defined in boto3.setup_default_session()
。
下面的代码在本地工作并将文件从目录上传到 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, or by passing a region_name
when creating the client object. A default region can also be defined in boto3.setup_default_session()
。