Azure TableService() returns python 产品中的 ValueError,但不是开发中的
Azure TableService() returns python ValueError in prod, but not dev
我有开发 Python 代码 运行 很棒,使用...
1 from azure.cosmosdb.table.tableservice import TableService
2 from azure.cosmosdb.table.models import Entity
...
85 table_service = TableService(connection_string = table_storage_connection_string)
86 perform_lookup = table_service.get_entity(mapping_table, 'test', 'foo')
将代码复制到 prod 并更改值后...
table_storage_connection_string
- Docs 说用
connection_string
就可以了。
- 已验证这是 Table 存储帐户的连接字符串
- 它在
local.settings.json
/Azure 门户应用设置 中使用 Key Vault 引用
mapping_table
...我得到错误:
Exception while executing function: Functions.my-func-prod <--- Result: Failure Exception: ValueError: You need to provide an account name and either an account_key or sas_token when creating a storage service. Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func return func(**params) File "/home/site/wwwroot/my-func-prod/__init__.py", line 85, in main table_service = TableService(connection_string = table_storage_connection_string) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/tableservice.py", line 173, in __init__ service_params = _TableServiceParameters.get_service_parameters( File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_connection.py", line 110, in get_service_parameters params = _ServiceParameters._from_connection_string(connection_string, service) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_connection.py", line 153, in _from_connection_string return _ServiceParameters(service, File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_connection.py", line 85, in __init__ raise ValueError(_ERROR_STORAGE_MISSING_INFO)
prop__StartTime 2020-10-16T04:50:07.099Z
prop__Duration 00:00:01.2898150
ProcessId 18
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.my-func-prod
为什么 TableService()
在带有连接字符串的开发中工作得很好,在产品中需要 Table 存储帐户名称和帐户密钥或 sas 令牌?
编辑 1:
当 connection_string
替换为存储帐户的 account_name
和 account_key
时,我在后续行中收到 new 错误( 89):
1 from azure.cosmosdb.table.tableservice import TableService
2 from azure.cosmosdb.table.models import Entity
...
85 table_service = TableService(
86 account_name = table_storage_account_name,
87 account_key = table_storage_account_key
88 )
89 perform_lookup = table_service.get_entity(mapping_table, 'test', 'foo')
新错误:
Exception while executing function: Functions.my-func-prod <--- Result: Failure Exception: AzureSigningError: Incorrect padding Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func return func(**params) File "/home/site/wwwroot/my-func-prod/__init__.py", line 89, in main perform_lookup = table_service.get_entity(mapping_table, 'test', 'foo') File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/tableservice.py", line 896, in get_entity return self._perform_request(request, _convert_json_response_to_entity, File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/tableservice.py", line 1106, in _perform_request return super(TableService, self)._perform_request(request, parser, parser_args, operation_context) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/storageclient.py", line 386, in _perform_request raise ex File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/storageclient.py", line 358, in _perform_request raise ex File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/storageclient.py", line 302, in _perform_request self.authentication.sign_request(request) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/_auth.py", line 35, in sign_request self._add_authorization_header(request, string_to_sign) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_auth.py", line 75, in _add_authorization_header raise _wrap_exception(ex, AzureSigningError)
有人用 Table 存储解决过这个问题吗?
我试图重现您的错误,但使用 connection_string 以及使用 account_name 和 account_key 都运行良好。
connection_string
同时包含AccountName
和AccountKey
,看起来像这样:
DefaultEndpointsProtocol=https;AccountName=<your-account-name>;AccountKey=<e60xxxxxxxxxxx==>;EndpointSuffix=core.windows.net
如果connection_string
不包含AccountName
或AccountKey
,就会出现错误。
错误(填充不正确)与您的帐户密钥不正确有关。请在门户中重新生成密钥并尝试使用新密钥。
我有开发 Python 代码 运行 很棒,使用...
1 from azure.cosmosdb.table.tableservice import TableService
2 from azure.cosmosdb.table.models import Entity
...
85 table_service = TableService(connection_string = table_storage_connection_string)
86 perform_lookup = table_service.get_entity(mapping_table, 'test', 'foo')
将代码复制到 prod 并更改值后...
table_storage_connection_string
- Docs 说用
connection_string
就可以了。 - 已验证这是 Table 存储帐户的连接字符串
- 它在
local.settings.json
/Azure 门户应用设置 中使用 Key Vault 引用
- Docs 说用
mapping_table
...我得到错误:
Exception while executing function: Functions.my-func-prod <--- Result: Failure Exception: ValueError: You need to provide an account name and either an account_key or sas_token when creating a storage service. Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func return func(**params) File "/home/site/wwwroot/my-func-prod/__init__.py", line 85, in main table_service = TableService(connection_string = table_storage_connection_string) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/tableservice.py", line 173, in __init__ service_params = _TableServiceParameters.get_service_parameters( File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_connection.py", line 110, in get_service_parameters params = _ServiceParameters._from_connection_string(connection_string, service) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_connection.py", line 153, in _from_connection_string return _ServiceParameters(service, File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_connection.py", line 85, in __init__ raise ValueError(_ERROR_STORAGE_MISSING_INFO)
prop__StartTime 2020-10-16T04:50:07.099Z
prop__Duration 00:00:01.2898150
ProcessId 18
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.my-func-prod
为什么 TableService()
在带有连接字符串的开发中工作得很好,在产品中需要 Table 存储帐户名称和帐户密钥或 sas 令牌?
编辑 1:
当 connection_string
替换为存储帐户的 account_name
和 account_key
时,我在后续行中收到 new 错误( 89):
1 from azure.cosmosdb.table.tableservice import TableService
2 from azure.cosmosdb.table.models import Entity
...
85 table_service = TableService(
86 account_name = table_storage_account_name,
87 account_key = table_storage_account_key
88 )
89 perform_lookup = table_service.get_entity(mapping_table, 'test', 'foo')
新错误:
Exception while executing function: Functions.my-func-prod <--- Result: Failure Exception: AzureSigningError: Incorrect padding Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func return func(**params) File "/home/site/wwwroot/my-func-prod/__init__.py", line 89, in main perform_lookup = table_service.get_entity(mapping_table, 'test', 'foo') File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/tableservice.py", line 896, in get_entity return self._perform_request(request, _convert_json_response_to_entity, File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/tableservice.py", line 1106, in _perform_request return super(TableService, self)._perform_request(request, parser, parser_args, operation_context) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/storageclient.py", line 386, in _perform_request raise ex File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/storageclient.py", line 358, in _perform_request raise ex File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/storageclient.py", line 302, in _perform_request self.authentication.sign_request(request) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/_auth.py", line 35, in sign_request self._add_authorization_header(request, string_to_sign) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/cosmosdb/table/common/_auth.py", line 75, in _add_authorization_header raise _wrap_exception(ex, AzureSigningError)
有人用 Table 存储解决过这个问题吗?
我试图重现您的错误,但使用 connection_string 以及使用 account_name 和 account_key 都运行良好。
connection_string
同时包含AccountName
和AccountKey
,看起来像这样:
DefaultEndpointsProtocol=https;AccountName=<your-account-name>;AccountKey=<e60xxxxxxxxxxx==>;EndpointSuffix=core.windows.net
如果connection_string
不包含AccountName
或AccountKey
,就会出现错误。
错误(填充不正确)与您的帐户密钥不正确有关。请在门户中重新生成密钥并尝试使用新密钥。