使用 Python 从公共 AWS S3 下载文件/文件夹,无需凭据 [英] Download file/folder from Public AWS S3 with Python, no credentials

查看:35
本文介绍了使用 Python 从公共 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 以及 Requests强> Python 中的库.如果您向匿名用户授予 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)

请求

GetObject

这篇关于使用 Python 从公共 AWS S3 下载文件/文件夹,无需凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆