I use CherryPy to run a very simple web server. It is designed to process parameters GETand, if they are true, do something with them.
import cherrypy
class MainServer(object):
def index(self, **params):
if 'a' in params:
print params['a']
index.exposed = True
cherrypy.quickstart(MainServer())
For example,
http://127.0.0.1:8080/abcde:
404 Not Found
The path '/abcde' was not found.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cherrypy\_cprequest.py", line 656, in respond
response.body = self.handler()
File "C:\Python27\lib\site-packages\cherrypy\lib\encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "C:\Python27\lib\site-packages\cherrypy\_cperror.py", line 386, in __call__
raise self
NotFound: (404, "The path '/abcde' was not found.")
Powered by CherryPy 3.2.4
I am trying to catch this exception and show a blank page because clients do not care about this. In particular, the result will be an empty object, regardless of the url string or query that led to the exception.
I looked at the error handling documentation cherrypy._cperror, but I did not find a way to use it.
EDIT : I gave up using CherryPyand found a simple solution using BaseHTTPServer(see my answer below, downvoted because it solves the problem but doesn't answer the question ... sigh ...)