Hello Is there any way to connect through a proxy using sockets in python. This is giving me an error
import soc开发者_高级运维ket, sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.python.org", 80))
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
soc.connect(("http://www.python.org",80))
File "<string>", line 1, in connect
gaierror: [Errno -5] No address associated with hostname
Thanks
You can try using SocksiPy: it'll establish a connection to your proxy server and do all that work for you.
I was able to solve this issue using urllib2
like so:
import urllib2
opener = urllib2.build_opener(
urllib2.ProxyHandler({"http":"proxy_ip_address:port_number";}),
urllib2.ProxyHandler({"https":"proxy_ip_address:port_number";}),
)
urllib2.install_opener(opener)
for line in urllib2.urlopen("py4inf.com/code/romeo.txt"):
print line.strip()
精彩评论