Unable to make python requests over tor ConnectionRefusedError: [WinError 10061]

廉价感情. 提交于 2021-02-10 18:39:57

问题


I am trying to make requests using python requests over tor, but i get the error "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it".

Here is the code i am using:

import requests

def get_tor_session():
    session = requests.session()
    # Tor uses the 9050 port as the default socks port
    session.proxies = {'http':  'socks5://127.0.0.1:9050',
                       'https': 'socks5://127.0.0.1:9050'}
    return session

# Make a request through the Tor connection
# IP visible through Tor
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
# Above should print an IP different than your public IP

# Following prints your normal public IP
print(requests.get("http://httpbin.org/ip").text)

I have tried disabling the firewall etc but can't seems to understand the problem, any help would be appreciated. I am using python 3.7 windows 10.


回答1:


Thanks for all the help, yes as already mentioned in the comments, there was something wrong with the proxy.

I changed:

session.proxies = {'http':  'socks5://127.0.0.1:9050',
                   'https': 'socks5://127.0.0.1:9050'}

To:

session.proxies = {'http':  'socks5://127.0.0.1:9150',
                   'https': 'socks5://127.0.0.1:9150'}

90 to 91 in address and it worked !



来源:https://stackoverflow.com/questions/59551276/unable-to-make-python-requests-over-tor-connectionrefusederror-winerror-10061

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!