这段代码工作得很好:
from azure.storage.blob import BlobServiceClient
from azure.identity import InteractiveBrowserCredential, DeviceCodeCredential, ClientSecretCredential
credential = DeviceCodeCredential(authority="login.microsoftonline.com", tenant_id="***", client_id="***")
blobber = BlobServiceClient(account_url="https://***.blob.core.windows.net", credential=credential)
blobs = blobber.list_containers()
for b in blobs:
print(b)
我运行它,浏览到 URL,填写我发出的代码,随后连接成功并返回容器列表。
但是,当我尝试切换到 InteractiveBrowserCredential 时:
credential = InteractiveBrowserCredential(authority="login.microsoftonline.com", tenant_id="***", client_id="***")
blobber = BlobServiceClient(account_url="https://***.blob.core.windows.net", credential=credential)
blobs = blobber.list_containers()
for b in blobs:
print(b)
浏览器确实打开,我获得了 token ,但身份验证失败并出现以下错误:
azure.core.exceptions.ClientAuthenticationError: Authentication failed: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
网上看类似问题,根本原因通常是应用程序没有在Azure AD中注册为PublicClient。然而,这里的情况并非如此。我确保该应用程序已注册为公共(public)客户端。事实上,第一个样本就完美地证明了这一点。
我在这里敲头。还有其他建议吗?
最佳答案
要使用InteractiveBrowserCredential,您需要在移动和桌面应用程序平台而非网络平台下添加重定向网址。如果您在 Web 平台下添加了重定向 url,则会遇到该问题。
您的代码运行良好。
关于python-3.x - 无法使用 InteractiveBrowserCredential 连接到 azure blob 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60191090/