Testing for connection to a website

Alexnb alexnbryan at gmail.com
Wed Jul 16 14:29:24 EDT 2008




Fredrik Lundh wrote:
> 
> 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>
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

Thanks! can't believe I didn't think of that. 

-- 
View this message in context: http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18493785.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list