Opened 12 years ago

Closed 11 years ago

#2742 closed defect (duplicate)

[patch] doesn't properly handle blank CONTENT LENGTH with patch

Reported by: anonymous Owned by: Adrian Holovaty
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:


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

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

Here is a patch:
replace line 122 with these:


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

Download all attachments as: .zip

Change History (5)

comment:1 Changed 12 years ago by Malcolm Tredinnick

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

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

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/", line 74, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

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

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

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 136, in _get_post

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", 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/", line 160, in _get_raw_post_data
    content_length = int(self.environ['CONTENT_LENGTH'])


Changed 11 years ago by Sergey <rushman@…>

Attachment: content_type_fix.diff added

Fix for empty CONTENT_TYPE bug

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

Summary: doesn't properly handle blank CONTENT LENGTH with patch[patch] doesn't properly handle blank CONTENT LENGTH with patch

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

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