Python 使用 azure-data-tables 从 Azure 存储表获取结果

Kru*_*kFu 4 python azure azure-table-storage

我正在尝试查询 Azure 存储表以将所有行转换为网站上的表,但是我无法从表中获取条目,每次都会收到相同的错误“azure.core.exceptions.HttpResponseError: The请求的操作未在指定资源上实现。”

对于代码,我按照此处的示例进行操作,但它没有按预期工作。

from azure.data.tables import TableServiceClient
from azure.core.credentials import AzureNamedKeyCredential

def read_storage_table():
    credential = AzureNamedKeyCredential(os.environ["AZ_STORAGE_ACCOUNT"], os.environ["AZ_STORAGE_KEY"])
    service = TableServiceClient(endpoint=os.environ["AZ_STORAGE_ENDPOINT"], credential=credential)
    client = service.get_table_client(table_name=os.environ["AZ_STORAGE_TABLE"])
    entities = client.query_entities(query_filter="PartitionKey eq 'tasksSeattle'")
    client.close()
    service.close()

    return entities
Run Code Online (Sandbox Code Playgroud)

然后调用该函数。

table = read_storage_table()
for record in table:
    for key in record.keys():
        print("Key: {}, Value: {}".format(key, record[key]))
Run Code Online (Sandbox Code Playgroud)

返回:

Traceback (most recent call last):
  File "C:\Program Files\Python310\Lib\site-packages\azure\data\tables\_models.py", line 363, in _get_next_cb
    return self._command(
  File "C:\Program Files\Python310\Lib\site-packages\azure\data\tables\_generated\operations\_table_operations.py", line 386, in query_entities
    raise HttpResponseError(response=response, model=error) 
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Not Implemented'
Content: {"odata.error":{"code":"NotImplemented","message":{"lang":"en-US","value":"The requested operation is not implemented on the specified resource.\nRequestId:cd29feda-1002-006b-679c-3d39e8000000\nTime:2022-03-22T03:27:00.5993216Z"}}}
Run Code Online (Sandbox Code Playgroud)

使用类似的函数我可以写入表。但即使尝试Entity = client.list_entities() 我也会得到同样的错误。我不知所措。

小智 6

KrunkFu感谢您在此确定并分享解决方案。将相同内容发布到答案部分以帮助其他社区成员。

将https://<accountname>.table.core.windows.net/<table>, 替换https://<accountname>.table.core.windows.net为查询解决了问题

  • 请投票关闭,因为“拼写错误或无法复制”。这只是OP的一个错误,他们修复了它。无需将他们的评论转换为答案。 (2认同)