#32162: Invalid 'Content-Length' header, and printing request body raises
exception
in POST requests using AsyncTestClient
-------------------------------------+-------------------------------------
Reporter: tmiller02 | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.1
Uncategorized | Keywords: AsyncTestClient,
Severity: Normal | AsyncRequestFactory
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
POST requests that are created using the AsyncTestClient do not seem to
have a valid 'Content-Length' header. In addition, attempting to print the
body of a POST request raises an exception (seemingly related to the
invalid 'Content-Length').
These issues can be demonstrated using AsyncRequestFactory:
{{{
>>> from django.test import AsyncRequestFactory
>>> rf = AsyncRequestFactory()
>>> post_request = rf.post('/submit/', {'foo': 'bar'})
>>> print(post_request.headers)
{'Host': 'testserver', 'Content-Length':
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
'Content-Type': 'multipart/form-data; boundary=BoUnDaRyStRiNg', 'Cookie':
''}
>>> print(post_request.body)
ValueError Traceback (most recent call
last)
/opt/my_project/venv/lib64/python3.6/site-packages/django/http/request.py
in body(self)
318 # Limit the maximum request data size that will be
handled in-memory.
319 if (settings.DATA_UPLOAD_MAX_MEMORY_SIZE is not None
and
--> 320 int(self.META.get('CONTENT_LENGTH') or 0) >
settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
321 raise RequestDataTooBig('Request body exceeded
settings.DATA_UPLOAD_MAX_MEMORY_SIZE.')
322
ValueError: invalid literal for int() with base 10:
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32162>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.7777d9d9c367c1e7ae1af7a3136f785c%40djangoproject.com.