【问题标题】:Raven - Sentry and Django: AttributeError: 'function' object has no attribute 'send'Raven - Sentry 和 Django:AttributeError:'function' 对象没有属性'send'
【发布时间】:2017-09-28 04:00:40
【问题描述】:

我在我的 django 项目中安装了 raven-python,./manage.py raven test 有效,但是当我想加载我的应用程序的任何页面时,我得到了很大的回溯(开发服务器正确启动):

Traceback (most recent call last): File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__ return self.application(environ, start_response) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 177, in __call__ signals.request_started.send(sender=self.__class__, environ=environ) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send response = receiver(signal=self, sender=sender, **named) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/contrib/django/models.py", line 209, in before_request self.client.context.activate() File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/contrib/django/models.py", line 55, in <lambda> __getattr__ = lambda x, o: getattr(get_client(), o) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/contrib/django/models.py", line 135, in get_client instance = Client(**options) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/contrib/django/client.py", line 138, in __init__ Client.__init__(self, *args, **kwargs) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/base.py", line 222, in __init__ self.hook_libraries(hook_libraries) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/base.py", line 275, in hook_libraries hook_libraries(libraries) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/breadcrumbs.py", line 364, in hook_libraries func() File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/utils/__init__.py", line 185, in new_func rv = func(*args, **kwargs) File "/home/vince/.virtualenvs/abelujo/lib/python2.7/site-packages/raven/breadcrumbs.py", line 286, in _hook_requests real_send = Session.send AttributeError: 'function' object has no attribute 'send'

我不知道去哪里调查。知道发生了什么吗? 谢谢。

raven/django documentation(我不使用设置结束时定义的客户端)。


我使用 django-whitenoise 来提供静态文件,设置在 wsgi.py 但它似乎没有任何影响(我禁用了它)。 Django 1.8 版,raven v6.0.0。

乌鸦配置:

RAVEN_CONFIG = { 'dsn': dsn, # If you are using git, you can also automatically configure the # release based on the git info. 'release': raven.fetch_git_sha(os.path.dirname(os.pardir)), }

我的中间件:

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

已安装的应用程序:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',  # for intcomma currency filter only (card show).
    'django_extensions',
    'bootstrap3',
    'bootstrap_admin',
    'django.contrib.admin',
    # Custom:
    'mod_wsgi.server',
    'huey.contrib.djhuey',
    'rest_framework',
    'raven.contrib.django.raven_compat',  # sentry
    'search', # my app
)

我的 wsig.py:

from django.core.wsgi import get_wsgi_application application = get_wsgi_application() application = DjangoWhiteNoise(application)


更新我在单元测试中遇到了同样的问题。我最终阻止了在调试模式下向 INSTALLED_APPS 添加哨兵:

if PROD:
    INSTALLED_APPS += 'raven.contrib.django.raven_compat'

并相应地加载记录器:

def get_logger():
    """Get the appropriate logger for PROD or DEBUG mode. On local
    development, don't use the sentry_logger (throws errors).
    """
    if settings.DEBUG:
        return logging.getLogger('debug_logger')
    else:
        return logging.getLogger('sentry_logger')

【问题讨论】:

    标签: django sentry


    【解决方案1】:

    不确定错误消息的原因,但我想对于初学者来说,您可以在中间件或 wsgi 中安装 Raven:https://docs.sentry.io/clients/python/integrations/django/#message-references

    【讨论】:

    • 谢谢指点!这个中间件没有用,但我在 wsgi 级别安装了一个(就在 django 的 get_wsgi_applicationbefore whitenoise 的中间件之后),它可以工作。 (我想如果您在答案中添加 wsgi 的提及,我可以接受:))
    • 不过,如果有人能解释一下……
    • 如果有机会,我会在 Raven 的源头四处挖掘。我怀疑这与您的白噪声 wsgi 包装器有关。
    • 请注意,当我在 wsgi.py 中停用 whitenoise 的中间件时也会出现错误消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2020-01-09
    • 2023-03-03
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多