Opened 2 years ago

Closed 2 years ago

#33926 closed Bug (duplicate)

Django freezes when reading data from request.body

Reported by: Maksim Khozyainov Owned by: nobody
Component: HTTP handling Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (3)

comment:1 by Claude Paroz, 2 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #29800

comment:2 by Maksim Khozyainov, 2 years ago

Resolution: duplicate
Status: closednew

comment:3 by Carlton Gibson, 2 years ago

Resolution: duplicate
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top