【问题标题】:invalid literal for int() with base 10: '基数为 10 的 int() 的无效文字:'
【发布时间】:2018-03-13 05:18:20
【问题描述】:

我最近在我的项目中添加了用于错误跟踪的哨兵,并根据文档 here 配置了 raven,但得到了如下所示的错误。

settings.py

​​>
import raven


INSTALLED_APPS = [    
    # 3rd party app
    'raven.contrib.django.raven_compat',
]    

RAVEN_CONFIG = {
    'dsn': 'https://*****@sentry.io/224093',
    'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
}

错误日志

System check identified no issues (0 silenced).
October 02, 2017 - 11:31:58
Django version 1.10, using settings 'FoodCham.settings.development'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Sending message of length 2240 to https://sentry.io/api/224093/store/
Internal Server Error: /
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 244, in _legacy_get_response
    response = middleware_method(request)
  File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/middleware/__init__.py", line 135, in process_request
    request.body  # forces stream to be read into memory
  File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 267, in body
    int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
ValueError: invalid literal for int() with base 10: ''
Internal Server Error: /
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)

  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 244, in _legacy_get_response
    response = middleware_method(request)
  File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/middleware/__init__.py", line 135, in process_request
    request.body  # forces stream to be read into memory
  File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 267, in body
    int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
ValueError: invalid literal for int() with base 10: ''
[02/Oct/2017 11:32:04] "GET / HTTP/1.1" 500 69274

任何有用的答案将不胜感激!

【问题讨论】:

  • 您的CONTENT_LENGTH 设置是什么?它不应为空。
  • 尝试将默认设置为'0' 而不是简单的0
  • @The_Cthulhu_Kid 我无法更改框架设置
  • self.META.get('CONTENT_LENGTH') 由服务器发送""。您应该更新服务器的设置,让它也发送内容长度。

标签: django python-2.7 sentry raven django-logging


【解决方案1】:

这是一个bug with a Django version。我安装了 Django 1.10 并看到了这个错误。问题中提到的升级到 1.10.8 解决了这个问题。

【讨论】:

    【解决方案2】:

    这是 Django 中的一个错误,而不是 raven 中的错误,它在 Django 1.10.8 中得到解决,只需将 django-1.10 升级到 django-1.10.8 就可以正常工作。

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 1970-01-01
      • 2021-06-25
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      相关资源
      最近更新 更多