#33926: Django freezes when reading data from request.body
-----------------------------------------+------------------------
Reporter: sfcl | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Let's say we have a simple Django view:
{{{
def my_view(request):
content = request.body
# some actions with content varible
response = HttpResponse('<h1>It work!</h1>')
}}}
And a simple api client, let's say based on the requests library, sending
malformed Django view data:
{{{
headers = dict()
headers['Accept'] = '*/*'
headers['Content-Length'] = '13409'
headers['Content-Type'] = 'application/x-compressed'
headers['Expect'] = '100-continue'
headers['Host'] = '127.0.0.1:8000'
headers['User-Agent'] = 'Api client'
headers['content-encoding'] = 'gzip'
url = 'http://127.0.0.1:8000/api'
request_body = ''
r = requests.post(
url,
data=request_body,
headers=headers
)
}}}
As you can see, request_body contains an empty string, but the Content-
Length header stores the value 13409. When such a request arrives, Django
hangs on the line reading request.body. No exceptions occur. How to solve
this problem? I cannot influence the client, so the only thing I can do is
rewrite the Django view. Django version 3.2.15 is used.
--
Ticket URL: <https://code.djangoproject.com/ticket/33926>
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/01070182a667747f-4960065a-010a-426c-9ca3-489f29dfcfcf-000000%40eu-central-1.amazonses.com.