Testing for connection to a website

Fredrik Lundh fredrik at pythonware.com
Wed Jul 16 11:16:28 CEST 2008


Alexnb wrote:

> e = ''

> try: 
>     ...
> except HTTPError, e:
>     print e.code
> except URLError, e:
>     print e.reason
>     
> if e == '':
>     print "good to go"

footnote: here's a better way to test if an exception was raised or not:

     try:
         ...
     except HTTPError, e:
         print e.code
     except URLError, e:
         print e.reason
     else:
         print "good to go"

</F>




More information about the Python-list mailing list