我试图使用Microsoft提供的示例,使用Python连接到Azure存储表。由于找不到TableStorage Account,下面的代码失败。我缺少的是我安装了azure软件包,但仍然抱怨找不到它
import azure.common
from azure.storage import CloudStorageAccount
from tablestorageaccount import TableStorageAccount
print('Azure Table Storage samples for Python')
# Create the storage account object and specify its credentials
# to either point to the local Emulator or your Azure subscription
if IS_EMULATED:
account = TableStorageAccount(is_emulated=True)
else:
account_connection_string = STORAGE_CONNECTION_STRING
# Split into key=value pairs removing empties, then split the pairs into a dict
config = dict(s.split('=', 1) for s in account_connection_string.split(';') if s)
# Authentication
account_name = config.get('AccountName')
account_key = config.get('AccountKey')
# Basic URL Configuration
endpoint_suffix = config.get('EndpointSuffix')
if endpoint_suffix == None:
table_endpoint = config.get('TableEndpoint')
table_prefix = '.table.'
start_index = table_endpoint.find(table_prefix)
end_index = table_endpoint.endswith(':') and len(table_endpoint) or table_endpoint.rfind(':')
endpoint_suffix = table_endpoint[start_index+len(table_prefix):end_index]
account = TableStorageAccount(account_name = account_name, connection_string = account_connection_string, endpoint_suffix=endpoint_suffix)
我找到了源示例代码,在示例代码中仍然有一个自定义模块
tablestorageaccount.py
,它只是用来返回TableService
。如果您已经有了存储连接字符串并希望进行测试,则可以直接连接到表样本:
您还可以参考新的sdk连接表。这是关于Get started with Azure Table storage的官方教程
相关问题 更多 >
编程相关推荐