Pyramid 1.2 with debugtoolbar + mongodb

62 vues
Accéder directement au premier message non lu

Adrien

non lue,
23 sept. 2011, 17:35:5923/09/2011
à pylons-discuss
Hi,

I'm trying to setup a Pyramid 1.2 + mongodb projet. I'm following the
recipe found here: https://docs.pylonsproject.org/projects/pyramid_cookbook/dev/mongo.html

However, the line below from __init__.py generates an internal error:
config.registry.settings['db_conn'] = conn #line 13 of the
cookbook

Here is the traceback:

Exception happened during processing of request from ('127.0.0.1',
58347)
Traceback (most recent call last):
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/Paste-1.7.5.1-py2.6.egg/paste/httpserver.py", line 1068, in
process_request_in_thread
self.finish_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 322, in
finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.6/SocketServer.py", line 617, in __init__
self.handle()
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/Paste-1.7.5.1-py2.6.egg/paste/httpserver.py", line 442, in
handle
BaseHTTPRequestHandler.handle(self)
File "/usr/lib/python2.6/BaseHTTPServer.py", line 329, in handle
self.handle_one_request()
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/Paste-1.7.5.1-py2.6.egg/paste/httpserver.py", line 437, in
handle_one_request
self.wsgi_execute()
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/Paste-1.7.5.1-py2.6.egg/paste/httpserver.py", line 287, in
wsgi_execute
self.wsgi_start_response)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid-1.2-py2.6.egg/pyramid/router.py", line 176, in
__call__
response = self.handle_request(request)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_debugtoolbar-0.9.3-py2.6.egg/pyramid_debugtoolbar/
toolbar.py", line 150, in toolbar_tween
toolbar.process_response(response)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_debugtoolbar-0.9.3-py2.6.egg/pyramid_debugtoolbar/
toolbar.py", line 50, in process_response
vars, request=request)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid-1.2-py2.6.egg/pyramid/renderers.py", line 69, in
render
return helper.render(value, None, request=request)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid-1.2-py2.6.egg/pyramid/renderers.py", line 418, in
render
result = renderer(value, system_values)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_jinja2-1.1-py2.6.egg/pyramid_jinja2/__init__.py",
line 277, in __call__
return self.template.render(system)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/Jinja2-2.6-py2.6.egg/jinja2/environment.py", line 894, in
render
return self.environment.handle_exception(exc_info, True)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_debugtoolbar-0.9.3-py2.6.egg/pyramid_debugtoolbar/
templates/toolbar.jinja2", line 62, in top-level template code
{{ panel.content()|safe }}
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_debugtoolbar-0.9.3-py2.6.egg/pyramid_debugtoolbar/
panels/settings.py", line 57, in content
vars, self.request)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_debugtoolbar-0.9.3-py2.6.egg/pyramid_debugtoolbar/
panels/__init__.py", line 24, in render
return render(template_name, vars, request=request)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid-1.2-py2.6.egg/pyramid/renderers.py", line 69, in
render
return helper.render(value, None, request=request)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid-1.2-py2.6.egg/pyramid/renderers.py", line 418, in
render
result = renderer(value, system_values)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_jinja2-1.1-py2.6.egg/pyramid_jinja2/__init__.py",
line 277, in __call__
return self.template.render(system)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/Jinja2-2.6-py2.6.egg/jinja2/environment.py", line 894, in
render
return self.environment.handle_exception(exc_info, True)
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pyramid_debugtoolbar-0.9.3-py2.6.egg/pyramid_debugtoolbar/
panels/templates/settings.jinja2", line 12, in top-level template code
<td>{{ value|escape }}</td>
File "/home/adrien/virtualenvs/pyramid1_2/lib/python2.6/site-
packages/pymongo-2.0.1-py2.6-linux-x86_64.egg/pymongo/database.py",
line 682, in __call__
"failing because no such method exists." % self.__name)
TypeError: 'Database' object is not callable. If you meant to call the
'__html__' method on a 'Connection' object it is failing because no
such method exists.


Now the error only shows up when the debug toolbar is included.
Also if I add a __html__ method to the connection with this line:
'conn.__html__ = lambda: "mongodb connection" ' , I can use both mongo
and the debug toolbar.
But this solution does not look so elegant...

Is there a new "official" way to use mongodb with pyramid 1.2 ?

Thanks,
Adrien

Chris McDonough

non lue,
23 sept. 2011, 17:45:0923/09/2011
à pylons-...@googlegroups.com

Your solution is fine, until we figure out a way to defeat PyMongo's
stupidity in the toolbar or cookbook entry.

- C

Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message