[BangPypers] catching exceptions from SimpleHTTPServer

2010-07-20 Thread Rahul R
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 ?

code snippet:
http://codepad.org/eKWUhrnO
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] catching exceptions from SimpleHTTPServer

2010-07-20 Thread Baiju M
On Tue, Jul 20, 2010 at 10:25 PM, Rahul R  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.0 +0530
+++ browser-new.py  2010-07-20 22:55:20.0 +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
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] catching exceptions from SimpleHTTPServer

2010-07-20 Thread Rahul R
>
> 
> --- browser.py  2010-07-20 22:51:33.0 +0530
> +++ browser-new.py  2010-07-20 22:55:20.0 +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()
> 
>
>
> negative aint working  , i tried a few changes myself . when i referred to
the class BaseHTTPServer s methods ( http://bit.ly/aYqnQE ) i found a
particular method log_message which is similar to sys.stderr but for some
reason it isnt appending ne data into the log file created.

the revised code snippet:
http://codepad.org/PRPXVUpY


--Rahul
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] catching exceptions from SimpleHTTPServer

2010-07-20 Thread steve

On 07/20/2010 11:45 PM, Rahul R wrote:

 negative aint working  , i tried a few changes myself . when i referred to
the class BaseHTTPServer s methods ( http://bit.ly/aYqnQE ) i found a
particular method log_message which is similar to sys.stderr but for some
reason it isnt appending ne data into the log file created.


Seems to be working for me:
http://codepad.org/MppnYU9n

I'm taking a wild guess here, you skimmed the docs and saw log_message() but 
didn't realize it is a method of the BaseHTTPRequestHandler class, *not* the 
HTTPServer class. Did I get that right ? can't blame you if I did, the docs are 
arranged in a such a manner that making this mistake is easy :).


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers