I have a Table within Azure data storage that I am trying to read from. I am able to successfully write to this table but unable to read. I have followed the docs here: https://learn.microsoft.com/en-us/python/api/overview/azure/data-tables-readme?view=azure-python
I also have a contributor role in IAM which should allow me to read and write.
My code is here:
credential = AzureNamedKeyCredential(os.environ['storage'], os.environ['azkey'])
service = TableServiceClient(endpoint=os.environ['azendpoint'], credential=credential)
az_table= service.get_table_client("az_table")
entities = df.apply(lambda x: json.loads(x.to_json()), axis=1)
[az_table.create_entity(entity) for entity in entities]
This now has entities in and I have checked this in the storage explorer. Here is the read that fails:
table_entities = az_table.query_entities(query_filter="PartitionKey eq 'somevalue'")
for entity in table_entities :
print(entity)
for key in entity.keys():
print(f"Key: {key}, Value: {entity[key]}")
I now get this error:
azure.core.exceptions.HttpResponseError: The requested operation is not implemented on the specified resource.
RequestId:893f445b-6002-0031-6fff-51613d000000
Time:2024-01-28T15:31:45.5859059Z
ErrorCode:NotImplemented
Content: {"odata.error":{"code":"NotImplemented","message":{"lang":"en-US","value":"The requested operation is not implemented on the specified resource.\nRequestId:893f445b-6002-0031-6fff-51613d000000\nTime:2024-01-28T15:31:45.5859059Z"}}}
I don't understand what I'm doing here and any help would be appreciated.
azure.core.exceptions.HttpResponseError: The requested operation is not implemented on the specified resource.
The above error occurs when you pass the wrong query expression or pass the wrong environment parameters in the code.
In my environment, I tried using the code below to create an entity with Azure Python SDK.
Code:
from azure.data.tables import TableServiceClient
from azure.core.credentials import AzureNamedKeyCredential
import json
import pandas as pd
credential = AzureNamedKeyCredential("venkat678","wxxvbxxxxxxx")
service = TableServiceClient("https://venkat678.table.core.windows.net", credential=credential)
az_table= service.get_table_client("aztable")
data = {'PartitionKey': ['partition1', 'partition2', 'partition3'],
'RowKey': ['row1', 'row2', 'row3'],
'Value': ['value1', 'value2', 'value3']}
df = pd.DataFrame(data)
entities = df.apply(lambda x: json.loads(x.to_json()), axis=1)
[az_table.create_entity(entity) for entity in entities]
Output:
Now, to query the entities, I used the code below with correct parameters.
Code:
from azure.data.tables import TableServiceClient
from azure.core.credentials import AzureNamedKeyCredential
import pandas as pd
credential = AzureNamedKeyCredential("venkat678","w5xxxx")
service = TableServiceClient("https://venkat678.table.core.windows.net/", credential=credential)
az_table= service.get_table_client("aztable")
table_entities = az_table.query_entities(query_filter="PartitionKey eq 'partition1'")
for entity in table_entities :
print(entity)
for key in entity.keys():
print(f"Key: {key}, Value: {entity[key]}")
Output:
{'PartitionKey': 'partition1', 'RowKey': 'row1', 'Value': 'value1'}
Key: PartitionKey, Value: partition1
Key: RowKey, Value: row1
Key: Value, Value: value1
Make sure your endpoint and table name are passed correctly in environment variables.
Reference: Python getting results from Azure Storage Table with azure-data-tables - Stack Overflow by KrunkFu.