【问题标题】:How to programmatically retrieve the connection string from an Azure storage account in Python如何以编程方式从 Python 中的 Azure 存储帐户检索连接字符串
【发布时间】:2021-04-11 18:40:16
【问题描述】:

假设您具有管理员访问权限,并且您刚刚在 Python 脚本中以编程方式创建了一个存储帐户。

然后如何从 Python 中新创建的存储帐户中检索连接字符串?例如,如果您想在同一个脚本中创建存储队列?

【问题讨论】:

    标签: python azure azure-storage


    【解决方案1】:

    如果您使用azure-mgmt-storage 创建存储帐户,则可以关注this article 获取连接字符串。

    这是上面示例中用于获取连接字符串的代码 sn-p:

    # 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}")
    

    【讨论】:

    • 非常有帮助,谢谢!还建议人们查看该文章,了解如何在查询连接字符串之前等待存储帐户配置完成。
    猜你喜欢
    • 2018-12-20
    • 1970-01-01
    • 2020-07-14
    • 2015-12-02
    • 2018-02-09
    • 2021-12-17
    • 2021-11-11
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多