Python 3.12 Sentry-sdk AttributeError:模块“collections”没有属性“MutableMapping”

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

我尝试使用

sentry-sdk
最新版本的 Python 3.12,但是当我运行我的 django 应用程序时,它显示以下错误:

AttributeError: module 'collections' has no attribute 'MutableMapping'

完整追踪如下:

File "/usr/local/lib/python3.12/site-packages/sentry_sdk/__init__.py", line 1, in <module>
from sentry_sdk.hub import Hub, init
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/hub.py", line 5, in <module>
from sentry_sdk.scope import Scope, _ScopeManager
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/scope.py", line 11, in <module>
from sentry_sdk.attachments import Attachment
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/attachments.py", line 5, in <module>
from sentry_sdk.envelope import Item, PayloadRef
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/envelope.py", line 6, in <module>
from sentry_sdk.session import Session
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/session.py", line 5, in <module>
from sentry_sdk.utils import format_timestamp
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/utils.py", line 1302, in <module>
HAS_REAL_CONTEXTVARS, ContextVar = _get_contextvars()
                                   ^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/utils.py", line 1272, in _get_contextvars
if not _is_contextvars_broken():
       ^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/utils.py", line 1213, in _is_contextvars_broken
from eventlet.patcher import is_monkey_patched  # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/eventlet/__init__.py", line 6, in <module>
from eventlet import convenience
File "/usr/local/lib/python3.12/site-packages/eventlet/convenience.py", line 7, in <module>
from eventlet.green import socket
File "/usr/local/lib/python3.12/site-packages/eventlet/green/socket.py", line 21, in <module>
from eventlet.support import greendns
File "/usr/local/lib/python3.12/site-packages/eventlet/support/greendns.py", line 78, in <module>
setattr(dns, pkg, import_patched('dns.' + pkg))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/eventlet/support/greendns.py", line 60, in import_patched
return patcher.import_patched(module_name, **modules)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/eventlet/patcher.py", line 132, in import_patched
return inject(
       ^^^^^^^
File "/usr/local/lib/python3.12/site-packages/eventlet/patcher.py", line 109, in inject
module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/dns/namedict.py", line 35, in <module>
class NameDict(collections.MutableMapping):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^

AttributeError:模块“collections”没有属性“MutableMapping”

python django sentry python-3.12
1个回答
0
投票

看起来您正在使用旧版本的

sentry-sdk

适用于

python 3.10
及以上

MutableMapping
移至
collections.abc

正确的导入是:

from collections.abc import MutableMapping

您需要升级

sentry-sdk

pip install --upgrade sentry-sdk

最新版本是

sentry-sdk 2.2.0

最近于2024年5月16日发布

enter image description here

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