mea*_*ari 6 amazon-s3 boto amazon-web-services boto3
在Boto中,我曾使用以下函数生成签名的URL.
import boto
conn = boto.connect_s3()
bucket = conn.get_bucket(bucket_name, validate=True)
key = bucket.get_key(key)
signed_url = key.generate_url(expires_in=3600)
Run Code Online (Sandbox Code Playgroud)
我如何在boto3中做同样的事情?
我搜索了boto3 GitHub 代码库但找不到对generate_url的单个引用.
功能名称是否已更改?
Joh*_*ein 13
从生成预配URL:
import boto3
import requests
# Get the service client.
s3 = boto3.client('s3')
# Generate the URL to get 'key-name' from 'bucket-name'
url = s3.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': 'bucket-name',
'Key': 'key-name'
}
)
# Use the URL to perform the GET operation. You can use any method you like
# to send the GET, but we will use requests here to keep things simple.
response = requests.get(url)
Run Code Online (Sandbox Code Playgroud)
功能参考: generate_presigned_url()
小智 8
\n\n\n当尝试访问普通浏览器中生成的 url \xe2\x80\x93 Aseem 2019 年 4 月 30 日 5:22 时,我收到错误 InvalidRequestThe授权机制不支持您提供的授权机制
\n
由于没有太多信息,我假设您遇到签名版本问题,如果没有,也许它会帮助其他人!:P
\n\n为此,您可以从 botocore 导入配置:-
\n\nfrom botocore.client import Config\nRun Code Online (Sandbox Code Playgroud)\n\n然后让客户端使用此配置并提供签名版本为“s3v4”
\n\ns3 = boto3.client('s3', config=Config(signature_version='s3v4'))\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
6003 次 |
| 最近记录: |