Azure 函数应用服务总线导入错误:无法导入名称"c_uamqp"



我有一个azure功能应用程序在消息发送到服务总线的事件中触发。代码逻辑工作得很好,我可以手动发送消息到服务总线,运行我的python代码来接收该消息,它工作得很好。

但是当我将这个逻辑集成到azure功能应用程序中时,我得到以下错误:

Result: Failure Exception: ImportError: cannot import name 'c_uamqp' from partially initialized module 'uamqp' (most likely due to a circular import) (/home/site/wwwroot/.python_packages/lib/site-packages/uamqp/__init__.py) Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 402, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 606, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/SentimentAnalysis/testServiceBus.py", line 10, in main from azure.servicebus import ServiceBusClient File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/servicebus/__init__.py", line 6, in <module> from uamqp import constants File "/home/site/wwwroot/.python_packages/lib/site-packages/uamqp/__init__.py", line 12, in <module> from uamqp import c_uamqp # pylint: disable=import-self

根据第一行,有一个循环导入错误,导致功能应用程序失败。

我的代码如下:

import logging
import azure.functions as func
import json
import boto3
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
from azure.servicebus import ServiceBusClient, ServiceBusMessage


def main(message: func.ServiceBusMessage):

我假设这个冲突发生在被导入两次的ServiceBusMessage上,但我不确定。

我在想,也许如果我摆脱了蔚蓝。使用azure.functions应该可以解决这个问题。但是检查这个库,我找不到任何方法来初始化ServiceBusClient

这种情况有没有发生在任何人身上,可以帮助我了解问题在哪里,我怎么可能解决它?

非常感谢您的帮助

当存在uamqp项目的本地副本,并且其路径被附加到PYTHONPATH时,会遇到这种类型的错误。

from azure.servicebus import ServiceBusClient,
ServiceBusMessage def  main(message: func.ServiceBusMessage): 
sb_client = ServiceBusClient.from_connection_string(...)

但是我知道ServiceBusService在v7.0.0中已被弃用https://pypi.org/project/azure-servicebus/7.0.0/

from azure.servicebus import ServiceBusClient, ServiceBusMessage

Azure SDK更新经常这样做,并引入了突破性的变化:0.2 ->0.5:

# From azure.servicebus import ServiceBusService <- This will now raise an ImportError
from azure.servicebus.control_client import ServiceBusService

0.5→7.0.0

#from azure.servicebus import ServiceBusService <-- Now outdated
from azure.servicebus.management import ServiceBusAdministrationClient 

根据上面的指南和你的版本兼容性来使用import语句。

但这还不够:请确保在此迁移指南中检查进一步的API更改:https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/servicebus/azure-servicebus/migration_guide.md

相关内容

  • 没有找到相关文章

最新更新