我正在嘗試連接到 azure blob 存盤(列出容器以檢查它是否有效),但是當我連接時出現身份驗證錯誤。這是我的代碼
from azure.storage.blob import BlockBlobService
top_level_container_name = "top_container"
sas_url ="https://secret.blob.core.windows.net/table?sv=2020-10-02&st=2022-05-16T10:11:57Z&se=2022-05-28T21:59:00Z&sr=c&sp=rl&sig=secret"
service=BlockBlobService(account_name="thi" ,sas_token=sas_url)
containers = service.list_containers()
for c in containers:
print(c.name)
運行時給我以下錯誤:
Traceback (most recent call last):
File "C:\Users\thijser\codes\python\listblobs.py", line 11, in <module>
containers = service.list_containers()
File "C:\Python310\lib\site-packages\azure\storage\blob\baseblobservice.py", line 514, in list_containers
resp = self._list_containers(**kwargs)
File "C:\Python310\lib\site-packages\azure\storage\blob\baseblobservice.py", line 558, in _list_containers
return self._perform_request(request, _convert_xml_to_containers, operation_context=_context)
File "C:\Python310\lib\site-packages\azure\storage\storageclient.py", line 280, in _perform_request
raise ex
File "C:\Python310\lib\site-packages\azure\storage\storageclient.py", line 248, in _perform_request
raise ex
File "C:\Python310\lib\site-packages\azure\storage\storageclient.py", line 235, in _perform_request
_http_error_handler(HTTPError(response.status, response.message, response.headers, response.body))
File "C:\Python310\lib\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.
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:2bc0650b-d01e-0050-511b-69cc86000000
Time:2022-05-16T11:54:26.0333719Z</Message><AuthenticationErrorDetail>Access without signed identifier cannot have time window more than 1 hour: Start [Mon, 16 May 2022 10:11:57 GMT] - Expiry [Sat, 28 May 2022 21:59:00 GMT]</AuthenticationErrorDetail></Error>
我可以使用相同的 sas 鏈接來查看 azure storage explorer 中的檔案。我通過 pip 新安裝了 1.5.0 版本的 azure blob 存盤。
有人知道如何擺脫錯誤嗎?sas 令牌不是由我生成的,實際上應該持續一整周。我懷疑它可能以某種方式涉及我的密碼(鑒于將 account_name 更改為無效的內容會更改錯誤),但我找不到如何正確添加它。我試過 service=BlockBlobService(account_name="thi", account_key = "my secret password", sas_token=sas_url)了,但這只是將錯誤更改為The MAC signature found in the HTTP request 'c5w tYbWVvibQ1NGFq0sHDwfvMS4wP0nO0d/iv5KuFo=' is not the same as any computed signature. Server used following string to sign: 'GET
編輯:
所以我發現我有一個服務 SAS 鏈接,而不是一個 SAS 帳戶。所以這將我的問題稍微改變為如何列出服務 sas url 中包含的所有內容?為此,我已經嘗試了幾個在線教程,但他們一直遇到錯誤:ImportError: cannot import name 'ContainerClient' from 'azure.storage.blob'. 有誰知道如何修復/列出此類鏈接中的所有檔案?
最后編輯:解決了。我必須卸載所有與 azure 相關的軟體包并安裝 azure-cli 軟體包。其次是 azure-storage-blob 包。
uj5u.com熱心網友回復:
您收到此錯誤的原因是您正在使用 aService SAS執行需要Account SAS. 列出 blob 容器操作需要帳戶 SAS,因為您在帳戶級別執行操作。
要修復此錯誤,您將需要至少具有以下屬性的 Account SAS:
- 簽名服務:Blob
- 簽名資源型別:服務(列出 blob 容器)和容器(列出容器內的 blob)
- 簽名權限:串列(用于串列操作)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/475927.html
上一篇:CA證書的OpenSSL擴展
