我正在尝试通过之前团队设计的管道在Azure中运行一些集成测试,但运气不佳。具体来说,管道不断遇到ClientAuthenticationError
.
这是崩溃前运行的Python代码的最小工作示例:
SAS_TOKEN = os.environ["SAS_TOKEN"]
credential = AzureSasCredential(SAS_TOKEN)
account_name = "ACCOUNT_NAME"
account_url = f"https://{account_name}.blob.core.windows.net"
container_name = "CONTAINER_NAME"
blob_service_client = BlobServiceClient(account_url, credential=credential)
container = blob_service_client.get_container_client(container_name)
parquet_names = container.list_blob_names(name_starts_with="PATTERN")
list_of_parquet = list(parquet_names)
这是上述代码产生的回溯:
File "/home/vsts/work/1/s/./tests/run_tests.py", line 24, in access_datalake_locally
list_of_parquet = list(parquet_names)
File "/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/azure/core/paging.py", line 123, in __next__
return next(self._page_iterator)
File "/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/azure/core/paging.py", line 75, in __next__
self._response = self._get_next(self.continuation_token)
File "/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/azure/storage/blob/_list_blobs_helper.py", line 175, in _get_next_cb
process_storage_error(error)
File "/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/azure/storage/blob/_shared/response_handlers.py", line 186, in process_storage_error
exec("raise error from None") # pylint: disable=exec-used # nosec
File "<string>", line 1, in <module>
azure.core.exceptions.ClientAuthenticationError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
我想到了一些可能出现问题的地方:
- 该
parquet_names
对象确实不喜欢被强制转换为list
。 - 我在构造该对象的方式上做了一些愚蠢的事情
credential
。(我尝试过blob_service_client = BlobServiceClient(account_url, credential=SAS_TOKEN
。遇到了完全相同的错误。) - 环境变量
SAS_TOKEN
错误。
如果您能就如何解决这种情况提出任何建议,我将不胜感激。
上述错误是由于 SAS 令牌的生成方式或传递到 Azure Blob 存储服务的方式造成的。
sas
您可以从门户生成令牌。门户网站:
存储帐户->共享访问签名->检查必填字段->生成SAS令牌。
我正在使用 Windows,因此我使用以下命令来存储
sas
来自门户的令牌。我同意 Gaurav Mantri 的评论,
sas
令牌的格式应该是这样的。代码和输出:
输出: