2017-04-30 37 views
0

我在我的django項目中安裝了raven-python,./manage.py raven test有效,但當我想加載我的任何頁面應用(開發服務器可以正常啓動):Raven - Sentry和Django:AttributeError:'function'對象沒有屬性'send'

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的白噪聲爲靜態文件,設置好的上wsgi.py,但它似乎並沒有產生任何影響(我禁用它)。 Django version 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') 

回答

1

不知道有關錯誤信息的原因,但我想對於初學者你可以在中間件或wsgi中安裝Raven:https://docs.sentry.io/clients/python/integrations/django/#message-references

+0

感謝或指針!這個中間件沒有用,但我在wsgi級別安裝了一個(在django的'get_wsgi_application'和**之前,** whitenoise的中間件之後),並且它工作正常。 (我想如果你在回答中加上提到的wsgi,我可以接受它:)) – Ehvince

+0

好吧,我已經這麼做了! – raiderrobert

+0

仍然,如果有人能解釋... – Ehvince