import urllib
import socket
socket.setdefaulttimeout(2) # timeout. increase for slow proxies
try:
urllib.urlopen(
"http://ya.ru",
proxies={'http':'http://example.com:8080'} # your proxy here
)
except IOError:
print "Bad proxy!" # do it if proxy connect is failed
else:
print "All was OK" # do it if all ok