我有一个 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.servicebus 并使用azure.functions
应该可以解决问题。但是检查这个库,我找不到任何方法来初始化ServiceBusClient
.
是否有任何人可以帮助我了解问题出在哪里以及如何解决?
非常感谢您的帮助