在触摸我的代码之前路由/挂架失败

时间:2010-10-02 17:44:25

标签: python regex routes pylons mod-wsgi

我对这个错误感到非常困惑。在以前功能正常的Pylons应用程序(在apache / mod_wsgi上运行)中,Routes爆炸了。当我尝试访问我的应用程序时,无论我使用什么URL,我都会在/var/log/apache2/error.log中获得Apache“内部服务器错误”页面和以下回溯。

[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

这让我感到非常困惑,因为看起来Routes在触及我的代码之前就会摔倒并死去 它唯一触及的是我的myapp.wsgi文件; myapp.wsgi和我的development.ini文件都没有在应用程序的最后工作状态和现在只有模型/控制器/模板文件之间发生变化。我还没有更新应用程序的最后一个工作状态和现在之间的任何包。我在我的应用程序中更改的文件是控制器,模型和模板文件 - 其中没有一个出现在回溯中。我以为我可能更改了routing.py而没有记住它,并且回溯导致正则表达式处理模块,所以我进入routing.py并注释掉所有使用Routes'requirements feature的行 - 没有变化,同样的错误。用很多apache2ctl restart重试 - 没有变化,同样的错误。

这里发生了什么蓝色火焰,以及我的应用中的可能导致了什么?

解决方案: 罪魁祸首是一条无辜的路线 -

map.redirect('/foo/*', '/', _redirect_code='301 Moved Permanently')

看起来像是星号使得Routes摇摆不定。我通过将匹配路径设置为'/foo/{bar}'然后将bar的值放在地板上来更正它。我仍然对为什么Routes遭遇崩溃而不是能够抛出类似SyntaxError的东西感到困惑,但是嘿,它现在有效。

1 个答案:

答案 0 :(得分:1)

我会查看你应用的config/routing.py文件,并在那里添加一些调试步骤,或尝试编辑或删除一些map.connect(...)调用。如果你一次注释掉每个控制器的映射,你可能能够缩小导致这种情况的一个控制器的映射。