I am very puzzled over this error. In a previously functional Pylons app (running on apache/mod_wsgi), Routes has exploded. When I attempt to access my application, no matter what URL I use, I get the Apache "Internal server error" page and the following traceback in /var/log/apache2/error.log.
[Sat Oct 02 2010] WSGI Variables
[Sat Oct 02 2010] --------------
[Sat Oct 02 2010] application: <beaker.middleware.SessionMiddleware object at 0xb885be6c>
[Sat Oct 02 2010] beaker.get_session: <bound method SessionMiddleware._get_session of <beaker.middleware.SessionMiddleware object at 0xb885be6c>>
[Sat Oct 02 2010] beaker.session: {'_accessed_time': 1286040208.138742, '_creation_time': 1286040208.138742}
[Sat Oct 02 2010] mod_wsgi.application_group: '192.168.1.51|'
[Sat Oct 02 2010] mod_wsgi.callable_object: 'application'
[Sat Oct 02 2010] mod_wsgi.handler_script: ''
[Sat Oct 02 2010] mod_wsgi.input_chunked: '0'
[Sat Oct 02 2010] mod_wsgi.listener_host: ''
[Sat Oct 02 2010] mod_wsgi.listener_port: '80'
[Sat Oct 02 2010] mod_wsgi.process_group: ''
[Sat Oct 02 2010] mod_wsgi.request_handler: 'wsgi-script'
[Sat Oct 02 2010] mod_wsgi.script_reloading: '1'
[Sat Oct 02 2010] mod_wsgi.version: (3, 3)
[Sat Oct 02 2010] paste.registry: <paste.registry.Registry object at 0xb7e373ac>
[Sat Oct 02 2010] paste.throw_errors: True
[Sat Oct 02 2010] wsgi process: 'Multi process AND threads (?)'
[Sat Oct 02 2010] wsgi.file_wrapper: <built-in method file_wrapper of mod_wsgi.Adapter object at 0xb70c77b8>
[Sat Oct 02 2010] wsgi.version: (1, 1)
[Sat Oct 02 2010] [client 192.168.1.50]
------------------------------------------------------------
[Sat Oct 02 2010] mod_wsgi (pid=13389): Exception occurred processing WSGI script '/var/pylons/myapp/myapp.wsgi'.
[Sat Oct 02 2010] Traceback (most recent call last):
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Paste-1.7.4-py2.7.egg/paste/cascade.py", line 130, in __call__
[Sat Oct 02 2010] return self.apps[-1](environ, start_response)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Paste-1.7.4-py2.7.egg/paste/registry.py", line 375, in __call__
[Sat Oct 02 2010] app_iter = self.application(environ, start_response)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Pylons-1.0-py2.7.egg/pylons/middleware.py", line 163, in __call__
[Sat Oct 02 2010] self.app, new_environ, catch_exc_info=True)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Pylons-1.0-py2.7.egg/pylons/util.py", line 48, in call_wsgi_application
[Sat Oct 02 2010] app_iter = application(environ, start_response)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/WebError-0.10.2-py2.7.egg/weberror/errormiddleware.py", line 156, in __call__
[Sat Oct 02 2010] return self.application(environ, start_response)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Beaker-1.5.4-py2.7.egg/beaker/middleware.py", line 152, in __call__
[Sat Oct 02 2010] return self.wrap_app(environ, session_start_response)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Routes-1.12.3-py2.7.egg/routes/middleware.py", line 84, in __call__
[Sat Oct 02 2010] results = self.mapper.routematch(environ=environ)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Routes-1.12.3-py2.7.egg/routes/mapper.py", line 690, in routematch
[Sat Oct 02 2010] result = self._match(url, environ)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Routes-1.12.3-py2.7.egg/routes/mapper.py", line 609, in _match
[Sat Oct 02 2010] self.create_regs()
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Routes-1.12.3-py2.7.egg/routes/mapper.py", line 560, in create_regs
[Sat Oct 02 2010] self._create_regs(*args, **kwargs)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Routes-1.12.3-py2.7.egg/routes/mapper.py", line 578, in _create_regs
[Sat Oct 02 2010] route.makeregexp(clist)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/site-packages/Routes-1.12.3-py2.7.egg/routes/route.py", line 306, in makeregexp
[Sat Oct 02 2010] self.regmatch = re.compile(reg)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/re.py", line 190, in compile
[Sat Oct 02 2010] return _compile(pattern, flags)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/re.py", line 243, in _compile
[Sat Oct 02 2010] p = sre_compile.compile(pattern, flags)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/sre_compile.py", line 500, in compile
[Sat Oct 02 2010] p = sre_parse.parse(p, flags)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/sre_parse.py", line 673, in parse
[Sat Oct 02 2010] p = _parse_sub(source, pattern, 0)
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/sre_parse.py", line 308, in _parse_sub
[Sat Oct 02 2010] itemsappend(_parse(source, state))
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/sre_parse.py", line 544, in _parse
[Sat Oct 02 2010] if not isname(name):
[Sat Oct 02 2010] File "/usr/local/lib/python2.7/sre_parse.py", line 218, in isname
[Sat Oct 02 2010] if not isident(name[0]):
[Sat Oct 02 2010] IndexError: string index out of range
This has me very confused because it appears that Routes falls over and dies before it ever touches my code! The only thing it touches is my myapp.wsgi file; neither myapp.wsgi nor my development.ini files have changed between the last working state of the app and now, only model/controller/template files. I have not updated any packages between the last working state of the app and now. The files that I have changed in my app are controller, model, and template files - none of which appear in the traceback. I thought that I might have changed routing.py without remembering it, and the traceback leads to the regular expression processing modules, so I went into routing.py and commented out all lines that use Routes' requirements feature - no change, same error. Retried with lots of apache2ctl restart
- no change, same error.
What in blue blazes is going on here, and what in my app might have caused it?
Solution: The culprit was an innocent-looking route -
map.redirect('/foo/*', '/', _redirect_code='301 Moved Permanently')
.
It looks like that bare asterisk made Routes throw a wobbly. I corrected it by making the match route into '/foo/{bar}'
and then dropping the value of bar on the floor. I'm still puzzled about why Routes suffered a meltdown over that instead of being able to throw something like a SyntaxError, but hey, it works now.