gpt4 book ai didi

python - SAS 访问 blob 容器 (azure/python)

转载 作者:太空宇宙 更新时间:2023-11-03 20:01:30 24 4
gpt4 key购买 nike

我想授予对我的帐户中的单个容器的有限访问权限,而不共享我的整个存储帐户 key 。我在 Azure 存储资源管理器中生成了特定于该容器的共享访问签名。

container right-click & generate SAS

example of output from generate SAS

当我尝试使用 blockblobservice 列出文件时,出现以下错误。使用 get_blob_to_path 时出现同样的错误。

from azure.storage.blob import BlockBlobService, BlobPermissions

sas_container = 'nwe-statements'
sas_token = '?st=2019-12-05T21%3A09%3A12Z&se=2020-01-31T21%3A13%3A00Z&sp=racwdl&sv=2018-03-28&sr=c&sig=YLk2UWxPcqkDl5a8nWtBYcw%3DxWuAsfFI1ch5TwrbAxvk'
example_file = '1470-4126.pdf'

def sas_list():
blob_service = BlockBlobService(account_name='pretend',sas_token=sas_token)
blob_list = blob_service.list_blobs(sas_container)
print(blob_list)

Traceback (most recent call last): File "/home/brett/jetco/django_jetco/O365/nwe_statements/blob_connect.py", line 24, in sas_list() File "/home/brett/jetco/django_jetco/O365/nwe_statements/blob_connect.py", line 11, in sas_list blob_list = blob_service.list_blobs(sas_container) File "/home/brett/jetco/env/lib/python3.6/site-packages/azure/storage/blob/baseblobservice.py", line 1214, in list_blobs resp = self._list_blobs(*args, **kwargs) File "/home/brett/jetco/env/lib/python3.6/site-packages/azure/storage/blob/baseblobservice.py", line 1285, in _list_blobs return self._perform_request(request, _convert_xml_to_blob_list, operation_context=_context) File "/home/brett/jetco/env/lib/python3.6/site-packages/azure/storage/storageclient.py", line 280, in _perform_request raise ex File "/home/brett/jetco/env/lib/python3.6/site-packages/azure/storage/storageclient.py", line 248, in _perform_request raise ex File "/home/brett/jetco/env/lib/python3.6/site-packages/azure/storage/storageclient.py", line 235, in _perform_request _http_error_handler(HTTPError(response.status, response.message, response.headers, response.body)) File "/home/brett/jetco/env/lib/python3.6/site-packages/azure/storage/_error.py", line 114, in _http_error_handler raise AzureHttpError(message, http_error.status) azure.common.AzureHttpError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:2d2370dc-f01e-0028-0fb3-ab47c9000000 Time:2019-12-05T21:33:23.3062345ZSignature did not match. String to sign used was racwdl

2020-01-31T21:13:00Z /blob/pretend/nwe-statements

2018-03-28

最佳答案

我可以重现您的问题,问题是由软件包引起的,请卸载旧的azure-storage并安装azure-storage-blob 2.1.0 ,然后就可以正常工作了。

pip uninstall azure-storage
pip install azure-storage-blob==2.1.0

enter image description here

enter image description here

此外,您应该注意到有一个新版本 v12 azure-storage-blob,它与 v2.1 不同版本。

v12 - https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python

v2.1 - https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python-legacy

关于python - SAS 访问 blob 容器 (azure/python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59203658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com