[英]failed to download files from AWS S3
塞纳里奥:
Error: An error occurred (404) when calling the HeadObject operation: Not Found
该文件存在于 S3 中很奇怪,我可以使用aws s3 cp
命令将其复制下来。 但是我就是无法使用 boto3 下载并且无法执行head-object
。
aws s3api head-object --bucket dsp-smaato-sink-prod --key /athena_query_results/c96bdc09-d545-4ee3-bc66-be3be928e3f2.csv
它确实有效。 我检查了帐户政策,它已授予管理政策。
# snippets
def s3_donwload(url, target=None):
# s3 = boto3.resource('s3')
# client = s3.meta.client
client = boto3.client("s3", region_name=constant.AWS_REGION, endpoint_url='https://s3.ap-southeast-1.amazonaws.com')
s3_file = urlparse(url)
if target:
target = os.path.abspath(target)
else:
target = os.path.abspath(os.path.basename(s3_file.path))
logger.info(f"download {url} to {target}...")
client.download_file(s3_file.netloc, s3_file.path, target)
logger.info(f"download {url} to {target} done!")
查看s3_file.path
的值——它是否以斜杠开头? 如果是这样,它需要更改,因为 Amazon S3 密钥不以斜杠开头。
我建议您打印netloc
、 path
和target
的内容,以查看它实际传递的值是什么。
将os.path
与 S3 URL 一起使用有点奇怪,因此可能需要进行一些调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.