Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simplest was is to simply catch the IOError exception from urllib:</p> <pre><code>try: urllib.urlopen( "http://example.com", proxies={'http':'http://example.com:8080'} ) except IOError: print "Connection error! (Check proxy)" else: print "All was fine" </code></pre> <p>Also, from <a href="http://love-python.blogspot.com/2008/07/check-status-proxy-address.html" rel="noreferrer">this blog post - "check status proxy address"</a> (with some slight improvements):</p> <pre><code>import urllib2 import socket def is_bad_proxy(pip): try: proxy_handler = urllib2.ProxyHandler({'http': pip}) opener = urllib2.build_opener(proxy_handler) opener.addheaders = [('User-agent', 'Mozilla/5.0')] urllib2.install_opener(opener) req=urllib2.Request('http://www.example.com') # change the URL to test here sock=urllib2.urlopen(req) except urllib2.HTTPError, e: print 'Error code: ', e.code return e.code except Exception, detail: print "ERROR:", detail return True return False def main(): socket.setdefaulttimeout(120) # two sample proxy IPs proxyList = ['125.76.226.9:80', '213.55.87.162:6588'] for currentProxy in proxyList: if is_bad_proxy(currentProxy): print "Bad Proxy %s" % (currentProxy) else: print "%s is working" % (currentProxy) if __name__ == '__main__': main() </code></pre> <p>Remember this could double the time the script takes, if the proxy is down (as you will have to wait for two connection-timeouts).. Unless you specifically have to know the proxy is at fault, handling the IOError is far cleaner, simpler and quicker..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload