Azure ServiceBusQueue使用uamqp依赖库时出现大量AttributeError调试日志问题排查与解决
This error is a known quirk with the uamqp 1.5.1 dependency used by azure-servicebus 7.6.0. It pops up during Python's garbage collection phase when the uamqp C extension tries to access an uninitialized logger (set to None) while cleaning up message objects. Even though your process exits successfully with code 0, those hundreds of repetitive error logs are definitely a nuisance.
Here are three reliable ways to fix this:
1. Manually initialize the uamqp logger
The quickest workaround is to explicitly set up the uamqp logger early in your script, before any service bus operations. This ensures the logger isn't None when the cleanup logic runs:
import logging import uamqp # Initialize the uamqp logger to avoid the None reference uamqp.logger = logging.getLogger("uamqp") # Optional: Set a log level to control uamqp's output (e.g., suppress debug logs) uamqp.logger.setLevel(logging.WARNING)
Add this snippet right at the top of your code, right after imports. This should eliminate the AttributeError logs entirely without touching your core service bus logic.
2. Upgrade to fixed package versions
The maintainers have patched this logger initialization issue in newer releases. You can upgrade both packages to their latest compatible versions:
pip install --upgrade azure-servicebus uamqp
For context, uamqp 1.5.2+ includes a direct fix for this problem, and newer azure-servicebus versions (7.7.0+) use updated uamqp dependencies that don't suffer from this bug. Just be sure to test your code after upgrading to confirm no compatibility breaks with your existing message processing flow.
3. Filter out the error logs (temporary hack)
If you can't upgrade packages or initialize the logger for some reason, you can configure Python's logging system to filter out these specific errors. This is a last-resort option since it doesn't fix the root cause, but it will clean up your console output:
import logging def filter_uamqp_debug_error(record): if record.exc_info: exc_type, exc_value, _ = record.exc_info if exc_type is AttributeError and "'NoneType' object has no attribute 'debug'" in str(exc_value): return False return True # Apply the filter to the uamqp logger logging.getLogger("uamqp").addFilter(filter_uamqp_debug_error)
After applying any of these fixes, run your script again—you should no longer see those hundreds of AttributeError lines, while your service bus message processing continues to work as expected.
内容的提问来源于stack exchange,提问作者Cribber

