Cannot connect to tor using python

I am trying to connect to TOR via python, but it does not allow me code:

def tor_connection(): socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050, True) socket.socket = socks.socksocket def main(): tor_connection() print('Connected to tor') con = httplib.HTTPConnection('myip.dnsomatic.com/') con.request('GET', '/') response = con.getresponse() print(response.read()) main() 

although it gives me the following error message:

 Traceback (most recent call last): File "C:/Users/anon/PycharmProjects/Scraper/tor.py", line 198, in <module> main() File "C:/Users/anon/PycharmProjects/Scraper/tor.py", line 194, in main con.request('GET', '/') File "C:\Python27\lib\httplib.py", line 1001, in request self._send_request(method, url, body, headers) File "C:\Python27\lib\httplib.py", line 1035, in _send_request self.endheaders(body) File "C:\Python27\lib\httplib.py", line 997, in endheaders self._send_output(message_body) File "C:\Python27\lib\httplib.py", line 850, in _send_output self.send(msg) File "C:\Python27\lib\httplib.py", line 812, in send self.connect() File "C:\Python27\lib\httplib.py", line 793, in connect self.timeout, self.source_address) File "C:\Python27\lib\socket.py", line 553, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11001] getaddrinfo failed 

I'm just a beginner, can someone help me please? I tried this on another laptop but its the same error message

+5
source share
1 answer

This is not a socks problem. You need to specify the host name without the ending / :

 >>> # with / >>> httplib.HTTPConnection('myip.dnsomatic.com/').request('GET', '/') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/httplib.py", line 973, in request self._send_request(method, url, body, headers) File "/usr/lib/python2.7/httplib.py", line 1007, in _send_request self.endheaders(body) File "/usr/lib/python2.7/httplib.py", line 969, in endheaders self._send_output(message_body) File "/usr/lib/python2.7/httplib.py", line 829, in _send_output self.send(msg) File "/usr/lib/python2.7/httplib.py", line 791, in send self.connect() File "/usr/lib/python2.7/httplib.py", line 772, in connect self.timeout, self.source_address) File "/usr/lib/python2.7/socket.py", line 553, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno -2] Name or service not known 

 >>> # without / >>> httplib.HTTPConnection('myip.dnsomatic.com').request('GET', '/') >>> 
0
source

Source: https://habr.com/ru/post/1212926/


All Articles