blobserviceclient的连接方式
BlobServiceClient可以通过以下方式进行连接:
- 使用连接字符串:可以将连接字符串作为参数传递给BlobServiceClient的构造函数。连接字符串包含Blob Storage的帐户名称和访问密钥等信息。
from azure.storage.blob import BlobServiceClient
connection_string = "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
- 使用URL和访问密钥:可以将Blob Storage的URL和访问密钥作为参数传递给BlobServiceClient的构造函数。
from azure.storage.blob import BlobServiceClient
account_url = "https://myaccount.blob.core.windows.net"
access_key = "myaccesskey"
blob_service_client = BlobServiceClient(account_url=account_url, credential=access_key)
- 使用托管标识:如果应用程序运行在Azure中,可以使用Azure托管标识来连接Blob Storage。此方法不需要提供访问密钥。
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
credential = DefaultAzureCredential()
blob_service_client = BlobServiceClient(account_url=account_url, credential=credential)
以上是连接Blob Storage的几种常见方式,根据实际情况选择合适的方法进行连接
原文地址: https://www.cveoy.top/t/topic/hyGS 著作权归作者所有。请勿转载和采集!