views:

94

answers:

1

I write this python code:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "64.83.219.7", 58279)
socket.socket = socks.socksocket
socket.setdefaulttimeout(19)
import urllib2
print urllib2.urlopen('http://www.google.com').read()

but when I execute it, I get this error:

urllib2.URLError: <urlopen error timed out>

What am I doing wrong?

+2  A: 

Something timed out in your script. I guess the connection to google because of wrong proxy setup. I think your goal is to fetch the contents of http://www.google.com through a proxy? I don't know about this method to set it using socket/socks module. Maybe you want to take a look at the following chapters in the python documentation:

http://docs.python.org/library/urllib2.html?highlight=urllib2#examples (code sinppet 5 and the text above)

http://docs.python.org/library/urllib2.html?highlight=urllib2#urllib2.Request.set_proxy

http://docs.python.org/library/urllib2.html?highlight=urllib2#proxyhandler-objects

rami