#27005 closed Bug (fixed)
request.body raises an exception if 'CONTENT_LENGTH' = ''
| Reported by: | Daniel | Owned by: | Tim Graham |
|---|---|---|---|
| Component: | HTTP handling | Version: | 1.10 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
invalid literal for int() with base 10:
/site-packages/django/http/request.py in body
line 267
# request.META['CONTENT_LENGTH'] = '' int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
Change History (13)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Environment:
Request Method: GET
Request URL: http://localhost:8000/myapp/
Django Version: 1.10
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "./python2.7/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "./python2.7/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "./python2.7/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/testproject/myapp/views.py" in test_view
7. assert False, request.body
File "./python2.7/site-packages/django/http/request.py" in body
267. int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
Exception Type: ValueError at /myapp/
Exception Value: invalid literal for int() with base 10: ''
comment:3 by , 9 years ago
comment:4 by , 9 years ago
Could you also show us what testproject.myapp.views.test_view looks like?
Thanks.
comment:5 by , 9 years ago
from django.shortcuts import render # Create your views here. def test_view(request): assert False, request.body
comment:6 by , 9 years ago
# testproject/testproject/urls.py """testproject URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.10/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^myapp/', include('myapp.urls')), url(r'^admin/', admin.site.urls), ]
# testproject/myapp/urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.test_view), ]
# testproject/myapp/views.py from django.shortcuts import render # Create your views here. def test_view(request): assert False, request.body
comment:7 by , 9 years ago
| Component: | Uncategorized → HTTP handling |
|---|---|
| Severity: | Normal → Release blocker |
| Summary: | request.body raises an exception → request.body raises an exception if 'CONTENT_LENGTH' = '' |
| Triage Stage: | Unreviewed → Accepted |
comment:8 by , 9 years ago
If it helps, here's a small testcase that reproduces the issue (it works on 1.9 but fails on 1.10):
from django.test import TestCase, RequestFactory class ReproTestCase(TestCase): def test_repro(self): request = RequestFactory().get('/', CONTENT_LENGTH='') self.assertEqual(request.META['CONTENT_LENGTH'], '') self.assertFalse(request.body)
comment:9 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Hi,
Thanks for reporting this issue to us.
Could you provide some information on how you managed to trigger this error? A full traceback would also be helpful.
Thanks.