Azure Function app:结果:失败异常:ImportError:无法从“azure.storage.blob”导入名称“BlobClient”(python)

问题描述 投票:0回答:1

得到

Result: Failure Exception: ImportError: cannot import name 'BlobClient' from 'azure.storage.blob'

运行http触发的azure函数应用程序时(python 3.10)

模块使用

from azure.storage.blob import BlobClient

导入

为了强制安装软件包,我使用

func azure functionapp publish fappname --build remote

部署了该功能

函数在本地环境运行成功。我已经尝试开发了好几次了,但都没有成功。

有什么想法吗?

需求.txt

aiofiles==23.2.1
aiohttp==3.9.3
aiosignal==1.3.1
async-timeout==4.0.3
attrs==23.2.0
azure-common==1.1.28
azure-core==1.30.1
azure-functions==1.18.0
azure-identity==1.15.0
azure-nspkg==3.0.2
azure-storage==0.36.0
azure-storage-blob==12.13.0
azure-storage-file-datalake==12.5.0
azure-storage-queue==12.4.0
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.5
frozenlist==1.4.1
idna==3.6
isodate==0.6.1
msal==1.28.0
msal-extensions==1.1.0
multidict==6.0.5
numpy==1.26.4
packaging==24.0
pandas==2.2.1
portalocker==2.8.2
pycparser==2.22
PyJWT==2.8.0
python-dateutil==2.9.0.post0
pytz==2024.1
requests==2.31.0
six==1.16.0
typing_extensions==4.11.0
tzdata==2024.1
urllib3==2.2.1
yarl==1.9.4

重新启动应用程序并使用

func azure functionapp publish fappname --build remote

重新部署它

还将 azure-storage-blob==12.13.0 更改为最新版本

python-3.x azure-functions
1个回答
0
投票

结果:失败异常:导入错误:无法从“azure.storage.blob”导入名称“BlobClient”

根据您遇到的错误 (

ImportError: cannot import name 'BlobClient' from 'azure.storage.blob'
),您的 Azure Function 应用程序中的包设置或环境似乎可能存在问题。

确保

azure-storage-blob
中指定的
requirements.txt
版本与 Azure Functions 运行时兼容。
azure-storage-blob
版本
12.13.0
应该没问题,但您可以尝试升级到可用的最新版本。

  • 检查 Azure Function 代码中的导入语句,如下所示:

    from azure.storage.blob import BlobClient

  • 由于冲突或安装不完整,可能会出现依赖性问题。尝试使用以下命令卸载环境并重新安装依赖项:

pip uninstall -r requirements.txt 
pip install -r requirements.txt
  • 另一种方法是使用 Visual Studio 代码将功能部署到门户中,如下所示:

enter image description here

然后选择门户中已创建的功能并按照如下所示操作:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.