[Grok-dev] Re: grok vs PostmortemDebuggingHTTP: 0-1

Philipp von Weitershausen philipp at weitershausen.de
Thu Aug 23 14:42:37 EDT 2007


Wichert Akkerman wrote:
> Previously Philipp von Weitershausen wrote:
>> Wichert Akkerman wrote:
>>> After upgrading grok to 0.10 in my buildout I can no longer use the
>>> PostmortemDebuggingHTTP server. A request to the Zope root drops me in
>>> pdb:
>> Right. Because the admin interface requires authorization. It seems that 
>> you haven't authorized yourself on that server/port yet. Any 
>> unauthorized access raises Unauthorized and you end up in pdb (instead 
>> of being deferred to a login screen). This isn't really grok's fault, 
>> this is just the way that the PostmortemDebuggingHTTP server works.
> 
> Interestingly PDBDebugMode in Zope 2 does not suffer from that problem,
> which makes me suspect there may be a better solution here.

This ain't Zope 2 :)

In short, what PostmortemDebuggingHTTP does is set the 
'wsgi.handleErrors' environment variable to False. This will cause the 
publication (in zope.app.publication) to *not* handle any exception. 
Instead the exception will simply propagate to wherever it's caught 
outside of the Zope publisher, in your case the PostmortemDebuggingHTTP 
server which invokes pdb. Unauthorized exceptions are no different.

My solution usually is to make sure my browser is authenticated before I 
enable such debugging means. I nowadays tend to use z3c.evalexception, 
an interactive AJAX debugger WSGI middleware based on [1]. I typically 
have the original application mounted at / and the debugging middlware 
wrapping the original application mounted at /debug. That way I can play 
around as usual with the application and when I counter an error, I 
repeat my steps using http://localhost:8080/debug/...

Realizing that the PostmortemDebuggingHTTP server solves a problem at 
completely the wrong end, I've decided to extend this package and also 
provide a PostMortemDebug middlware. It's released as z3c.evalexception 
2.0. To achieve what I've described in the previous paragraph, you would 
edit your PasteDeploy configuration file like so:

   [composite:main]
   use = egg:Paste#urlmap
   / = app
   /debug = debug

   [filter-app:debug]
   use = egg:z3c.evalexception#pdb
   next = app

   [app:app]
   use = egg:MyZopeApp

   [server:main]
   use = egg:Paste#http
   host = 127.0.0.1
   port = 8080

Naturally, this requires your application being WSGI- and Paste-aware, 
e.g. having been created through zopeproject [2] or my grokproject 
branch [3] that's based on zopeproject.


[1] http://pythonpaste.org/module-paste.evalexception.html
[2] http://cheeseshop.python.org/pypi/zopeproject
[3] http://svn.zope.org/grokproject/branches/use-zopeproject/

-- 
http://worldcookery.com -- Professional Zope documentation and training


More information about the Grok-dev mailing list