2

Hello Is there any way to connect through a proxy using sockets in python. This is giving me an error

import socket, 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

2 Answers 2

1

You can try using SocksiPy: it'll establish a connection to your proxy server and do all that work for you.

Sign up to request clarification or add additional context in comments.

Comments

0

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() 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.