本文介绍了使用Python从Public AWS S3下载文件/文件夹,无需凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经公开访问了S3存储桶,我需要使用python从存储桶中下载文件/包含文件的文件夹.诀窍是我不想提供凭据(boto3显然需要此凭据).甚至有可能吗?
I have opened a public access to S3 bucket and I need to download files / folders with files from the bucket using python. The trick is that I do not want to supply credentials (which boto3 apparently requires). Is it even possible?
推荐答案
您可以将 S3 REST API中的 GetObject 与请求一起使用库".如果您授予匿名用户READ权限,则可以不使用授权标头而返回对象.
You can use GetObject from the S3 REST API, together with the Requests library in Python. If you grant READ access to the anonymous user, you can return the object without using an authorization header.
此类S3 REST调用的示例:
Example of a such a S3 REST call::
> GET /example-object HTTP/1.1
> Host: example-bucket.s3.<Region>.amazonaws.com
Python(粗略的示例):
Python(rough example):
import requests
url = '/example-object'
headers = {'Host': 'example-bucket.s3.<Region>.amazonaws.com'}
r = requests.get(url, headers=headers)
这篇关于使用Python从Public AWS S3下载文件/文件夹,无需凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!