Opened 9 years ago

Closed 9 years ago

#2742 closed defect (duplicate)

[patch] core.handlers.wsgi.py doesn't properly handle blank CONTENT LENGTH with patch

Reported by: anonymous Owned by: adrian
Component: Core (Other) Version: master
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I was getting some strange errors trying to do some AJAX-type stuff and kept getting a strange traceback. I traced it to the wsgi.py:122.

if CONTENT LENGTH = , it fails with a Value Error.

Here is a patch:
replace line 122 with these:

try:

self._raw_post_data = self.environwsgi.input?.read(int(self.environCONTENT_LENGTH?))

except ValueError:

self._raw_post_data = self.environwsgi.input?.read(0)

return self._raw_post_data

Corey Oordt

Attachments (1)

content_type_fix.diff (579 bytes) - added by Sergey <rushman@…> 9 years ago.
Fix for empty CONTENT_TYPE bug

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by mtredinnick

Do you need the read(0) here instead of just setting self._raw_post_data = '' ?

comment:2 Changed 9 years ago by Sergey <rushman@…>

  • Severity changed from normal to major

I've encountered this bug too.

When I'm POSTing empty form under Lighttpd it does not sets CONTENT_LENGTH variable, and Django fails

Here is my traceback:

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 74, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/var/aromagic/aromagic/trunk/src/aromagic/manage/priceitem/views.py", line 65, in _wrapped_view_func
    data = view_func(request, *args, **kwargs)

  File "/var/aromagic/aromagic/trunk/src/aromagic/manage/priceitem/views.py", line 161, in assign_variation
    new_data = request.POST.copy()

  File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 136, in _get_post
    self._load_post_and_files()

  File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 116, in _load_post_and_files
    self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict()

  File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 160, in _get_raw_post_data
    content_length = int(self.environ['CONTENT_LENGTH'])

KeyError: 'CONTENT_LENGTH'

Changed 9 years ago by Sergey <rushman@…>

Fix for empty CONTENT_TYPE bug

comment:3 Changed 9 years ago by Sergey <rushman@…>

  • Summary changed from core.handlers.wsgi.py doesn't properly handle blank CONTENT LENGTH with patch to [patch] core.handlers.wsgi.py doesn't properly handle blank CONTENT LENGTH with patch

comment:4 Changed 9 years ago by Ivan Sagalaev <Maniac@…>

  • Resolution set to duplicate
  • Status changed from new to closed

Sorry, I've overlooked this ticket and filed a dupe today: #3057
But since that ticket is already applied I'm marking this one as a dupe instead.

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