I have a small Pyramid application that by default used the waitress web server when I set it up. However I am now trying to switch to CherryPy since it works much better with sse.
But for uncaught exceptions I got a 500 error page with content in waitress, but using cherrypy the pages are just blank (the status is correctly 500 though).
The only thing I did to switch was to change the line:
use = egg:waitress#main
to
use = egg:pyramid#cherrypy
In the documentation for CherryPy I can read that I can set a custom error message for an unanticipated error. Tried that out but I saw no effect at all, the function is never called - I even tried to add a breakpoint to CherryPy's internal error response but it was not hit either.
I suspect something else is wrong though since I assume CherryPy should show "something" by default for a 500 page ?
I have attempted to reproduce the issue using the starter
scaffold that comes with Pyramid, and made the following modification to the existing views.py
that it comes with:
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPInternalServerError
@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
raise HTTPInternalServerError()
On both CherryPy and waitress this returns a page with the HTTPInternalServerError()
on it including the text.
Changing the raise to:
raise ValueError('test')
However only shows something on the page if the pyramid_debugtoolbar
is enabled, and the user accessing the URL is allowed to see the pyramid_debugtoolbar
(this is controlled by the hosts
setting for pyramid_debugtoolbar
).
CherryPy does not have its own text. Unfortunately I don't see a way to use the _cp_config
method of enabling custom error messages, as there is no way to set it up on the HTTP server that is used when using the CherrypyWSGIServer
which is used by the Pyramid cherrypy
entrypoint used by pserve.
What you can do, is set up a default exception view in Pyramid such as the following:
@view_config(context=Exception)
def exception_view(request):
request.response.status = 500
request.response.text = u'Something went very wrong. Sorry!'
return request.response
You can off course customise this exception view however you'd like. If this exception view raises however, you will be at the mercy of CherryPy who will serve you a blank page.