Opened 18 years ago
Closed 16 years ago
#3762 closed (duplicate)
TypeError/Unhandled exception in django.core.handlers.base.get_response() if PATH_INFO is not in env
Reported by: | Ionuț Ciocîrlan | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | django_trac@…, john@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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 by , 18 years ago
Summary: | WSGI: obscure crash with missing PATH_INFO → TypeError/Unhandled exception in django.core.handlers.base.get_response() if PATH_INFO is not in env |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 18 years ago
comment:3 by , 17 years ago
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 by , 17 years ago
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 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → 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 by , 17 years ago
comment:7 by , 17 years ago
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 by , 17 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
Triage Stage: | Accepted → 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 by , 17 years ago
Cc: | 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:11 by , 16 years ago
Cc: | added |
---|---|
Resolution: | duplicate |
Status: | closed → 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 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Still a duplicate of #3414.
i got the some problem
lighttpd+mod_scgi win32