[Django] #33926: Django freezes when reading data from request.body

10 views
Skip to first unread message

Django

unread,
Aug 16, 2022, 7:26:18 AM8/16/22
to django-...@googlegroups.com
#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.

Django

unread,
Aug 16, 2022, 7:35:57 AM8/16/22
to django-...@googlegroups.com
#33926: Django freezes when reading data from request.body
-------------------------------+--------------------------------------
Reporter: sfcl | Owner: nobody
Type: Bug | Status: closed

Component: HTTP handling | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #29800

--
Ticket URL: <https://code.djangoproject.com/ticket/33926#comment:1>

Django

unread,
Aug 18, 2022, 1:24:57 AM8/18/22
to django-...@googlegroups.com
#33926: Django freezes when reading data from request.body
-----------------------------------+--------------------------------------
Reporter: Maksim Khozyainov | Owner: nobody
Type: Bug | Status: new

Component: HTTP handling | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Maksim Khozyainov):

* status: closed => new
* resolution: duplicate =>


--
Ticket URL: <https://code.djangoproject.com/ticket/33926#comment:2>

Django

unread,
Aug 18, 2022, 1:49:59 AM8/18/22
to django-...@googlegroups.com
#33926: Django freezes when reading data from request.body
-----------------------------------+--------------------------------------
Reporter: Maksim Khozyainov | Owner: nobody
Type: Bug | Status: closed

Component: HTTP handling | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => duplicate


Comment:

Hi Maksim.

Claude marked this as a duplicate. If you don't agree, and want to reopen,
could you also provide a comment as to why you think it's distinct.
Otherwise let's continue on #29800. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/33926#comment:3>

Reply all
Reply to author
Forward
0 new messages