我已经成功使用
BlobServiceClient.from_connection_string()
来获取BlobServiceClient
的实例。我们的基础设施还需要能够通过 linked service
连接。我在 BlobServiceClient API 中没有看到该容量。这怎么办?
链接服务:Microsoft Learn 链接服务
要从 synapse 链接服务获取连接,请在您的 synapse 笔记本中使用以下代码。
# Get the connection string
import json
print(json.loads(mssparkutils.credentials.getPropertiesAll("Blob_LS"))['AuthKey'])
#Create instance from
from azure.storage.blob import BlobServiceClient
service = BlobServiceClient(account_url="https://<storage_account_name>.blob.core.windows.net", credential=json.loads(mssparkutils.credentials.getPropertiesAll("<linked_service_name>"))['AuthKey'])
print("Instance created")
containers = service.list_containers(include_metadata=True)
for i in containers:
print(i['name'])
输出:
您还可以使用下面的 REST API 在普通 python 中获取连接字符串。
GET {endpoint}/linkedservices/{linkedServiceName}?api-version=2020-12-01
在 python get 请求中使用上述 REST API,并从 JSON 响应中获取所需的连接字符串。查看文档示例以获取更多信息。