【问题标题】:NameError: global name 'DEV_ACCOUNT_NAME' is not defined - Azure Storage EmulatorNameError:未定义全局名称“DEV_ACCOUNT_NAME”-Azure 存储模拟器
【发布时间】:2016-09-26 08:27:58
【问题描述】:

我正在尝试在我的 python 应用程序中使用 Azure Storage Emulator,但出现以下错误:

from azure.storage.table import TableService, Entity

#Added after error
global DEV_ACCOUNT_NAME
DEV_ACCOUNT_NAME = "devstoreaccount1"

table_service = TableService(account_name='devstoreaccount1', account_key='Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',)

table_service.use_local_storage = True
table_service.is_emulated = True

table_service.create_table("test")

错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_util.py", line 7
6, in exec_file
    exec(code_obj, global_variables)
  File "c:\ScratchApp\ScratchApp.py", line 17, in <module>
    table_service.create_table("test")
  File "C:\Python27\lib\site-packages\azure\storage\table\tableservice.py", line
 274, in create_table
    request, self.use_local_storage)
  File "C:\Python27\lib\site-packages\azure\storage\_common_serialization.py", l
ine 212, in _update_request_uri_query_local_storage
    return '/' + DEV_ACCOUNT_NAME + uri, query
NameError: global name 'DEV_ACCOUNT_NAME' is not defined
Press any key to continue . . .

有什么想法吗?

【问题讨论】:

  • 在一个模块中将变量声明为全局变量不会神奇地使其对其他模块可见。但是,为了解决您的具体问题,这可能是一个已知问题 (github.com/Azure/azure-storage-python/issues/58),该问题已在不久前修复。您有最新版本的 azure 存储模块吗?
  • 升级成功了 - 谢谢。还必须将 TableService 构造函数更改为:TableService(account_name='devstoreaccount1', account_key='Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==', protocol="http") 您应该将其发布为答案。

标签: python azure azure-storage azure-storage-emulator


【解决方案1】:

在一个模块中将变量声明为全局变量不会神奇地使其对其他模块可见。

不过,为了解决您的具体问题,看起来这可能是不久前修复的known issue。是否有最新版本的 azure 存储模块?

【讨论】:

  • 这个答案是完全正确的,但是使用模拟器还有更简单的方法。而不是直接使用这些内部常量设置帐户名和密钥,只需设置is_emulated=True。这将自动正确设置所有内容,包括协议。
猜你喜欢
  • 2011-04-27
  • 1970-01-01
  • 1970-01-01
  • 2018-02-13
  • 1970-01-01
  • 2014-10-24
  • 2012-05-29
  • 2013-08-23
相关资源
最近更新 更多