简体   繁体   English

我可以匿名使用 boto3 吗?

[英]Can I use boto3 anonymously?

With boto I could connect to public S3 buckets without credentials by passing the anon= keyword argument.使用boto我可以通过传递anon=关键字参数连接到没有凭据的公共 S3 存储桶。

s3 = boto.connect_s3(anon=True)

Is this possible with boto3 ?这可以用boto3吗?

Yes.是的。 Your credentials are used to sign all the requests you send out, so what you have to do is configure the client to not perform the signing step at all.您的凭据用于对您发出的所有请求进行签名,因此您需要做的是将客户端配置为根本不执行签名步骤。 You can do that as follows:你可以这样做:

import boto3
from botocore import UNSIGNED
from botocore.client import Config

s3 = boto3.client('s3', config=Config(signature_version=UNSIGNED))
# Use the client

Disable signing禁用签名

import boto3

from botocore.handlers import disable_signing
resource = boto3.resource('s3')
resource.meta.client.meta.events.register('choose-signer.s3.*', disable_signing)

None of these seem to work as of the current boto3 version (1.9.168).从当前的 boto3 版本 (1.9.168) 开始,这些似乎都不起作用。 This hack (courtesy of an unfixed github issue on botocore) does seem to do the trick:这个 hack(由 botocore 上未修复的 github 问题提供)似乎确实可以解决问题:

client = boto3.client('s3', aws_access_key_id='', aws_secret_access_key='')
client._request_signer.sign = (lambda *args, **kwargs: None)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM