disabling TCP connections, just for one script

Adam Monsen haircut at gmail.com
Fri Sep 9 17:03:58 EDT 2005


Another solution is using a deliberately misconfigured proxy:

import socket
socket.setdefaulttimeout(1)
import urllib
proxies = {'http': 'http://www.example.com:3128'}
url = 'http://www.google.com/'
opener = urllib.FancyURLopener(proxies)
f = opener.open(url)
print f.read()


>From this code I get the following exception:
"IOError: [Errno socket error] timed out"

...and that fits my needs nicely.

-- 
Adam Monsen
http://adammonsen.com/




More information about the Python-list mailing list