Opened 8 years ago

Closed 7 years ago

#3762 closed (duplicate)

TypeError/Unhandled exception in django.core.handlers.base.get_response() if PATH_INFO is not in env

Reported by: xlotlu Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: django_trac@…, john@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If the PATH_INFO env var is not set, django will crash on the first call to django.core.handlers.base.get_response() with "TypeError: unpack non-sequence".

That, if CommonMiddleware is not enabled. Otherwise: Unhandled Exception.

Ticket #3414 seems to be an effect of this same problem.

This bug was triggered under lighttpd when setting server.error-handler-404.

Change History (12)

comment:1 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from WSGI: obscure crash with missing PATH_INFO to TypeError/Unhandled exception in django.core.handlers.base.get_response() if PATH_INFO is not in env
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 8 years ago by anonymous

i got the some problem

lighttpd+mod_scgi win32

comment:3 Changed 8 years ago by xiang.can@…

It seems a windows specific problem. I got the same version of lighttpd running under linux and windows. By observing the "environ" from WSGIRequest I found windows version actually give the wrong PATH_INFO. A awkward work around can be done like the following:

replace:

self.path = environPATH_INFO?

with:

if environ.get('SCGI', None):

self.path = environREQUEST_URI?.split('?')[0]

else:

self.path = environPATH_INFO?

comment:4 Changed 8 years ago by anonymous

I ran into this problem running django (svn 5427 2007-06-02) on Dreamhost with fastcgi. PATH_INFO is empty in this environment, for whatever reason.

When APPEND_SLASH was set to False, I would get the exception described above.
When APPEND_SLASH was set to True, I would get the behavior described in #3414.

Applying the wsgi.patch from #3414 resolved the problem for me in both cases.

comment:5 Changed 7 years ago by ubernostrum

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

Closing as a duplicate of #3414 since the patch there is reported to fix this, and they appear to be the same underlying issue.

comment:6 Changed 7 years ago by michael@…

I got this error ("TypeError: unpack non-sequence") with a fairly standard setup: Debian Etch, Apache2 (prefork), mod-wsgi 1.3 (manually compiled), Python 2.4, and Django Trunk (7088).

Applying the patch from #3414 seems to have fixed it. PATH_INFO was indeed blank when I was receiving this error.

comment:7 Changed 7 years ago by michael@…

Followup: Removed the patch and instead applied the PATH_INFO hacks from the middle of this page: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Works perfectly with no Django hacks needed.

comment:8 Changed 7 years ago by ben at mymart dot com

  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Accepted to Unreviewed

I encountered this error under Apache and mod_python on Linux. I'm using the Scan Alert Hackersafe vulnerability scanning service. It seems one of the things they do is post a request that is probably something like:

GET * HTTP/1.1
Host: ...

This minimal case causes the error. I can't see the exact request they're sending my server.

Here's the traceback.

Traceback (most recent call last):

 File "/var/www/mymart/django/core/handlers/base.py", line 73, in get_response
   callback, callback_args, callback_kwargs = resolver.resolve(request.path)

TypeError: unpack non-sequence


<ModPythonRequest
path:*,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'AUTH_TYPE': None,
'CONTENT_LENGTH': 0L,
'CONTENT_TYPE': None,
'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_HOST': 'mymart.com',
'PATH_INFO': '',
'PATH_TRANSLATED': None,
'QUERY_STRING': None,
'REMOTE_ADDR': '212.56.54.20',
'REMOTE_HOST': None,
'REMOTE_IDENT': None,
'REMOTE_USER': None,
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': None,
'SERVER_NAME': 'mymart.com',
'SERVER_PORT': 0,
'SERVER_PROTOCOL': 'HTTP/1.1',
'SERVER_SOFTWARE': 'mod_python'}>

This error is definitely present in SVN rev 7438.

comment:9 Changed 7 years ago by jedie

  • Cc django_trac@… added

Think i have the same problem with django SVN and apache, fastcgi, modrewrite. If a search bot requests directly the index.fcgi file, i the the error, too:

Traceback (most recent call last):

 File "/var/www/mymart/django/core/handlers/base.py", line 73, in get_response
   callback, callback_args, callback_kwargs = resolver.resolve(request.path)

TypeError: unpack non-sequence

The problem is IMHO if request.path is empty:

        urlconf = settings.ROOT_URLCONF
        resolver=RegexURLResolver(r'^/', urlconf)
        print resolver.resolve("/")
        print resolver.resolve("") # <- the problem

output:

(<function index at 0x8a8d6f4>, ('',), {})
None

My work-a-round: Define a mod_rewrite rule like this:

# Request directly the index.fcg, send 403 HTTP response (FORBIDDEN)
RewriteRule ^index.fcgi$ - [F,L]

comment:10 Changed 7 years ago by jacob

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

Duplicate of #3414.

comment:11 Changed 7 years ago by anonymous

  • Cc john@… added
  • Resolution duplicate deleted
  • Status changed from closed to reopened

I'm able to replicate this bug with the help of django.test.client.Client; see the following:

Heima:MyProject john$ ./django-admin shell
Python 2.4.4 (#1, Oct 18 2006, 10:34:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.test.client import Client
>>> c = Client()

>>> c.get('/with-slash/')
<django.http.HttpResponseNotFound object at 0x19ece50>

>>> c.get('without-slash/')
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "/Users/john/Projects/MyProject/myproject/lib/django/test/client.py", line 218, in get
    return self.request(**r)
  File "/Users/john/Projects/MyProject/myproject/lib/django/core/handlers/base.py", line 73, in get_response
    callback, callback_args, callback_kwargs = resolver.resolve(request.path)
TypeError: unpack non-sequence

>>> c.get('/with-slash/') # Fails this time
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "/Users/john/Projects/MyProject/myproject/lib/django/test/client.py", line 218, in get
    return self.request(**r)
  File "/Users/john/Projects/MyProject/myproject/lib/django/core/handlers/base.py", line 73, in get_response
    callback, callback_args, callback_kwargs = resolver.resolve(request.path)
TypeError: unpack non-sequence

It feels like requesting a URL without a leading slash should work, as it's checked for in the flat-pages views.

Running Django trunk, r7569.

comment:12 Changed 7 years ago by mattmcc

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

Still a duplicate of #3414.

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