无法通过Python WebJob中的azure-storage包访问blob存储

时间:2016-09-27 17:58:37

标签: python azure azure-storage azure-storage-blobs azure-webjobs

我正在尝试使用Azure App Service上的Python WebJob从blob存储读取/写入。 My App Service的requirements.txt文件包含azure-storage软件包名称:在App Service部署期间通过pip成功安装软件包。但是,当我在WebJob的run.py文件中包含以下内容时:

import sys
sys.path.append('D:\\home\\site\\wwwroot\\env\\Lib\\site-packages')
from azure.storage.blob import BlockBlobService

...我在运行时收到以下错误消息:

[09/27/2016 17:51:09 > 775106: SYS INFO] Status changed to Initializing
[09/27/2016 17:51:09 > 775106: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost'
[09/27/2016 17:51:09 > 775106: SYS INFO] Status changed to Running
[09/27/2016 17:51:10 > 775106: ERR ] Traceback (most recent call last):
[09/27/2016 17:51:10 > 775106: ERR ]   File "run.py", line 11, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from azure.storage.blob import BlockBlobService
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\blob\__init__.py", line 15, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from .models import (
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\blob\models.py", line 15, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from .._common_conversion import _to_str
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\_common_conversion.py", line 22, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from .models import (
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\models.py", line 23, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from ._error import (
[09/27/2016 17:51:10 > 775106: ERR ]   File "D:\home\site\wwwroot\env\Lib\site-packages\azure\storage\_error.py", line 15, in <module>
[09/27/2016 17:51:10 > 775106: ERR ]     from ._common_conversion import _to_str
[09/27/2016 17:51:10 > 775106: ERR ] ImportError: cannot import name '_to_str'
[09/27/2016 17:51:10 > 775106: SYS INFO] Status changed to Failed
[09/27/2016 17:51:10 > 775106: SYS ERR ] Job failed due to exit code 1

FWIW,使用相同的方法正确加载了其他几个包。任何人都可以建议一种方法来让Azure Azure WebJobs中的azure-storage包工作吗?

1 个答案:

答案 0 :(得分:1)

看起来缺少六个模块。此问题也通过以下线程进行跟踪:https://github.com/Azure/azure-storage-python/issues/22。您可以通过将六个模块添加到requirements.txt或通过pip install six手动安装六个模块来解决问题。