如何以编程方式从 Python 中的 Azure 存储帐户检索连接字符串
How to programmatically retrieve the connection string from an Azure storage account in Python
假设您拥有管理员权限,并且刚刚在 Python 脚本中以编程方式创建了一个存储帐户。
然后如何从 Python 中新创建的存储帐户检索连接字符串?例如,如果您想在同一个脚本中创建存储队列?
如果您使用 azure-mgmt-storage to create the storage account, then you can follow this article 获取连接字符串。
这是上面示例中用于获取连接字符串的代码片段:
# Step 3: Retrieve the account's primary access key and generate a connection string.
keys = storage_client.storage_accounts.list_keys(RESOURCE_GROUP_NAME, STORAGE_ACCOUNT_NAME)
print(f"Primary key for storage account: {keys.keys[0].value}")
conn_string = f"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName={STORAGE_ACCOUNT_NAME};AccountKey={keys.keys[0].value}"
print(f"Connection string: {conn_string}")
假设您拥有管理员权限,并且刚刚在 Python 脚本中以编程方式创建了一个存储帐户。
然后如何从 Python 中新创建的存储帐户检索连接字符串?例如,如果您想在同一个脚本中创建存储队列?
如果您使用 azure-mgmt-storage to create the storage account, then you can follow this article 获取连接字符串。
这是上面示例中用于获取连接字符串的代码片段:
# Step 3: Retrieve the account's primary access key and generate a connection string.
keys = storage_client.storage_accounts.list_keys(RESOURCE_GROUP_NAME, STORAGE_ACCOUNT_NAME)
print(f"Primary key for storage account: {keys.keys[0].value}")
conn_string = f"DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName={STORAGE_ACCOUNT_NAME};AccountKey={keys.keys[0].value}"
print(f"Connection string: {conn_string}")