0

我一直在尝试使用 Python 获取用户委托密钥来签署容器 SAS,但它一直失败。我确定我在身份上做错了什么,但是从所有文档和示例中我无法弄清楚是什么。

这是我的代码:

account_url = f"https://{account_name}.blob.core.windows.net"

from datetime import datetime, timedelta
from azure.identity import DefaultAzureCredential

credential = DefaultAzureCredential(exclude_interactive_browser_credential=False)

from azure.storage.blob import BlobServiceClient
blob_service_client = BlobServiceClient(account_url=account_url, credential=credential)

udk = blob_service_client.get_user_delegation_key(key_start_time=datetime.utcnow() - timedelta(hours=1), key_expiry_time=datetime.utcnow() + timedelta(hours=1))

这是输出:

EnvironmentCredential.get_token failed: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ImdsCredential.get_token failed: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
ManagedIdentityCredential.get_token failed: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential.get_token failed: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
VisualStudioCodeCredential.get_token failed: Failed to get Azure user details from Visual Studio Code.
Traceback (most recent call last):
  File "C:/Tools/AzureTranslate/Test1/auth.py", line 11, in <module>
    udk = blob_service_client.get_user_delegation_key(key_start_time=datetime.utcnow() - timedelta(hours=1), key_expiry_time=datetime.utcnow() + timedelta(hours=1))
  File "C:\Users\\AppData\Roaming\Python\Python39\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "C:\Users\\AppData\Roaming\Python\Python39\site-packages\azure\storage\blob\_blob_service_client.py", line 205, in get_user_delegation_key
    process_storage_error(error)
  File "C:\Users\\AppData\Roaming\Python\Python39\site-packages\azure\storage\blob\_shared\response_handlers.py", line 89, in process_storage_error
    raise storage_error
  File "C:\Users\\AppData\Roaming\Python\Python39\site-packages\azure\storage\blob\_blob_service_client.py", line 201, in get_user_delegation_key
    user_delegation_key = self._client.service.get_user_delegation_key(key_info=key_info,
  File "C:\Users\\AppData\Roaming\Python\Python39\site-packages\azure\storage\blob\_generated\operations\_service_operations.py", line 441, in get_user_delegation_key
    map_error(status_code=response.status_code, response=response, error_map=error_map)
  File "C:\Users\\AppData\Roaming\Python\Python39\site-packages\azure\core\exceptions.py", line 105, in map_error
    raise error
azure.core.exceptions.ClientAuthenticationError: Operation returned an invalid status 'Server failed to authenticate the request. Please refer to the information in the www-authenticate header.'

所有帮助将不胜感激!

4

0 回答 0