金字塔配置加载错误

时间:2011-04-24 10:32:47

标签: python configuration pyramid

我在Pyramid中创建应用时遇到了问题。当我尝试通过贴纸服务时,我得到:

  File "/home/viraptor/blah/blah/__init__.py", line 23, in main
    return config.make_wsgi_app()
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 916, in make_wsgi_app
    self.commit()
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 491, in commit
    self._ctx.execute_actions()
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/zope/configuration/config.py", line 626, in execute_actions
    callable(*args, **kw)
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 1291, in register
    derived_view = deriver(view)
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 2681, in __call__
    self.mapped_view(view))))))))
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 2624, in inner
    wrapped_view = wrapped(self, view)
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 2693, in mapped_view
    mapped_view = mapper(**self.kw)(view)
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 2860, in __call__
    view = self.map_nonclass(view)
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 2876, in map_nonclass
    ronly = requestonly(view, self.attr)
  File "/home/viraptor/pyramid/lib/python2.6/site-packages/pyramid/config.py", line 2966, in requestonly
    if len(args) - len(defaults) == 1:
zope.configuration.config.ConfigurationExecutionError: <type 'exceptions.TypeError'>: object of type 'NoneType' has no len()
  in:
  ('/home/viraptor/blah/blah/__init__.py', 22, 'main', "config.add_route('customer', '/customer/{customer_id}', view='blah.views.customer.view', view_renderer='customer_view.mak', view_permission='view', traverse='/customer/{customer_id}')")

这可能是什么原因?我最近甚至没有更改过该配置,只有应用程序的其余部分。

2 个答案:

答案 0 :(得分:3)

我怀疑你遇到了金字塔新修订版中修复的错误;您的追溯表明argsdefaultsNone,但除非args不是None,否则无法访问该代码分支,可能会defaults 1}}而不是None。我发现以下对Pyramids的提交为defaults添加了一个特定的测试:None:

https://github.com/Pylons/pyramid/commit/f168197609169fb01b65adeb3eb59d069000fe2c

我说你有一个没有任何默认值的方法,只有一个请求参数(method(self, request),解决办法是添加一个默认的关键字参数(method(self, request, dummy=None)

免责声明:还没有机会与Pyramid合作,所以我的分析完全基于Pyramid代码库。

答案 1 :(得分:0)

config.add_route只接受1个位置参数,你的第二个参数应该与pattern使用keyworded。

其次,我认为routetraverse的模式不一样。使用traverse关键字,您可以确定root应该从哪里开始。它在Configurator API documentation中解释。

引发的错误异常可能会提供更多信息。