使用 Raspbian 下的 Python 访问 Azure 存储上的 Table 服务

Access Table Service on Azure Storage with Python under Raspbian

我在 Raspberian 下使用 Python 设置 Raspberry 3 / Sense Hat 组合与 Azure 存储 Table 服务之间的连接时遇到一些问题。按照 https://docs.microsoft.com/en-us/azure/storage/storage-python-how-to-use-table-storage 上的教程,我使用的代码是(当然是插入了 myaccountkey):

from sense_hat import SenseHat
from azure.storage.table import TableService

sense = SenseHat()

table_service = TableService(account_name='sensehat',
                         account_key=<myaccountkey>)
table_name = 'sensehatdata'
table_service.create_table(table_name, False)

错误回溯是:

Traceback (most recent call last):
  File "/home/pi/senseHat2Azure.py", line 22, in <module>
table_service.create_table(table_name, False)
  File "/usr/local/lib/python2.7/dist-packages/azure/storage/table/tableservice.py", line 281, in create_table
self._perform_request(request)
  File "/usr/local/lib/python2.7/dist-packages/azure/storage/storageclient.py", line 171, in _perform_request
resp = self._filter(request)
  File "/usr/local/lib/python2.7/dist-packages/azure/storage/table/tableservice.py", line 667, in _perform_request_worker
return self._httpclient.perform_request(request)
  File "/usr/local/lib/python2.7/dist-packages/azure/storage/_http/httpclient.py", line 181, in perform_request
self.send_request_body(connection, request.body)
  File "/usr/local/lib/python2.7/dist-packages/azure/storage/_http/httpclient.py", line 143, in send_request_body
connection.send(request_body)
  File "/usr/local/lib/python2.7/dist-packages/azure/storage/_http/requestsclient.py", line 81, in send
self.response = self.session.request(self.method, self.uri, data=request_body, headers=self.headers, timeout=self.timeout)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 407, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

我的存储帐户的一些详细信息:

非常感谢任何想法。

您收到此错误的原因是您的存储帐户的冗余类型。 ZRS 冗余类型的存储帐户仅支持 blob,不支持表和队列。

来自博客 post 宣布 this

As you can see, these options provide a continuum of durability and availability options. ZRS fits between LRS and GRS in terms of durability and price. ZRS stores 3 replicas of your data across 2 to 3 facilities. It is designed to keep all 3 replicas within in a single region, but may span across two regions. ZRS currently only supports block blobs. ZRS allows customers to store blob at a higher durability than a single facility can provide with LRS. ZRS accounts do not have metrics or logging capability enabled at this time.

由于您无法更改 ZRS 和其他(LRS、GRS、RAGRS)之间的冗余类型,您唯一的选择是创建一个新的存储帐户。创建标准存储帐户并选择冗余类型作为以下之一:LRS、GRS 或 RAGRS。当您使用该存储帐户时,您将不会看到此错误。