Connect to .onion websites using python?

Here is the code that I still have

import socks
import socket
import requests
import json

socks.setdefaultproxy(proxy_type=socks.PROXY_TYPE_SOCKS5, addr="127.0.0.1", port=9050)
socket.socket = socks.socksocket

data = json.loads(requests.get("http://freegeoip.net/json/").text)

and it works great. The problem is that when I use the URL .onionit shows an error

Failed to establish a new connection: [Errno -2] Name or service unknown

After a little research, I found that although the HTTP request was made over tor, the permission still extends to clearnet. What is the correct way, so I can also allow the domain allowed through the network to connect to the .onionurls?

+4
source share
1 answer

. , .

import requests
import json

proxies = {
    'http': 'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
}

data = requests.get("http://altaddresswcxlld.onion",proxies=proxies).text

print(data)

, socks5h://, DNS SOCKS, Tor .onion.

+3

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


All Articles