#32162 closed Bug (fixed)
AsyncTestClient crashes on requests with JSON data.
Description ¶
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
Change History (5)
comment:1 by , 4 years ago
Component: | Uncategorized → Testing framework |
---|
comment:2 by , 4 years ago
Cc: | added |
---|---|
Has patch: | set |
Owner: | changed from | to
Severity: | Normal → Release blocker |
Status: | new → assigned |
Summary: | Invalid 'Content-Length' header, and printing request body raises exception in POST requests using AsyncTestClient → AsyncTestClient crashes on requests with JSON data. |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Thanks for the report!
PR
#32164 was closes as a duplicate.