gpt4 book ai didi

python - 调用CopyObject操作时NoSuchBucket

转载 作者:太空宇宙 更新时间:2023-11-03 21:04:21 24 4
gpt4 key购买 nike

我尝试从 s3 中的旧文件恢复文件,前提是该文件不存在。我当前的代码是这样的:

import botocore
import os

s3 = boto3.resource('s3')

def checkFile(filename, buckett="selfmarkett"):
try:
s3.Object(buckett, filename).load()
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
try:
_filename, _extension = os.path.splitext(filename)
oldFilename = _filename + ".p_up" + _extension
s3.Object(buckett, filename).copy_from(CopySource=oldFilename)
except Exception as error:
print("Error2:", error)

我的问题是,当脚本尝试使用函数 copy_from 时,返回此错误:

NoSuchBucket: An error occurred (NoSuchBucket) when calling the CopyObject operation: The specified bucket does not exist

存储桶已在对象中指定,我该如何修复此错误?

最佳答案

我遇到了同样的问题,我通过在 CopySource 的路径中添加存储桶名称来修复它,如下所示:

s3.Object(bucket, "new_folder/new_file").copy_from(CopySource="<bucket>/old_folder/old_file")

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

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