Fetching a .onion domain with requests

前端 未结 1 1646
北恋
北恋 2021-01-21 16:20

I\'m trying to access the following domain nzxj65x32vh2fkhk.onion using requests.
I have tor running and I configured the session\'s object proxies correctly.

相关标签:
1条回答
  • 2021-01-21 16:43

    The solution is to use the socks5h protocol in order to enable remote DNS resolving in case the local DNS resolving process fails. See https://github.com/kennethreitz/requests/blob/e3f89bf23c53b98593e4248054661472aacac820/requests/packages/urllib3/contrib/socks.py#L158

    The following code works as expected:

    import requests
    session = requests.session()
    session.proxies = {'http':  'socks5h://localhost:9050',
                       'https': 'socks5h://localhost:9050'}
    print(session.get('http://httpbin.org/ip').text) # prints {"origin": "67.205.146.164" }
    
    print(requests.get('http://httpbin.org/ip').text) # prints {"origin": "5.102.254.76" }
    
    print(session.get('http://nzxj65x32vh2fkhk.onion/all').text) # Prints the contents of the page
    
    0 讨论(0)
提交回复
热议问题