[BangPypers] catching exceptions from SimpleHTTPServer
Baiju M
mbaiju at zeomega.com
Tue Jul 20 19:28:35 CEST 2010
On Tue, Jul 20, 2010 at 10:25 PM, Rahul R <rahul8590 at gmail.com> wrote:
> how to catch exceptions from the simpleHTTPServer . ( srry if this sounds
> ridiculous )
> the below is a small code snippet for a basic webserver . every time
> whenever there is a HTTP GET/POST request i can see the feedback in the
> terminal . how do i catch those feedbacks ?
Those are standard error messages (sys.stderr), you can get it like this:
--------------------------------------------
--- browser.py 2010-07-20 22:51:33.000000000 +0530
+++ browser-new.py 2010-07-20 22:55:20.000000000 +0530
@@ -18,4 +18,10 @@
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
-httpd.serve_forever()
+import sys
+out = open("browser.log", "w")
+sys.stderr = out
+try:
+ httpd.serve_forever()
+except:
+ out.close()
--------------------------------------------
I hope you can understand unified diff format: http://en.wikipedia.org/wiki/Diff
Regards,
Baiju M
More information about the BangPypers
mailing list