Opened 18 years ago

Closed 18 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 Holovaty
Component: Core (Other) Version: dev
Severity: major Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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@…> 18 years ago.
Fix for empty CONTENT_TYPE bug

Download all attachments as: .zip

Change History (5)

comment:1 by Malcolm Tredinnick, 18 years ago

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

comment:2 by Sergey <rushman@…>, 18 years ago

Severity: normalmajor

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'

by Sergey <rushman@…>, 18 years ago

Attachment: content_type_fix.diff added

Fix for empty CONTENT_TYPE bug

comment:3 by Sergey <rushman@…>, 18 years ago

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

comment:4 by Ivan Sagalaev <Maniac@…>, 18 years ago

Resolution: duplicate
Status: newclosed

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