【问题标题】:Unable to make python requests over tor ConnectionRefusedError: [WinError 10061]无法通过 tor ConnectionRefusedError 发出 python 请求:[WinError 10061]
【发布时间】:2020-04-20 09:45:15
【问题描述】:

我正在尝试使用 python 请求通过 tor 发出请求,但我收到错误“ConnectionRefusedError: [WinError 10061] 无法建立连接,因为目标机器主动拒绝了它”。

这是我正在使用的代码:

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)

我已尝试禁用防火墙等,但似乎无法理解问题所在,我们将不胜感激。我正在使用 python 3.7 windows 10。

【问题讨论】:

  • socks.ProxyConnectionError: 连接到 SOCKS5 代理 127.0.0.1:9050 时出错:[WinError 10061] 由于目标机器主动拒绝,无法建立连接
  • 当我尝试使用 tor 发出请求时遇到的问题,除此之外,请求完美无缺。
  • 您的代理似乎没有运行或由于某种原因不接受请求。您可以使用嗅探器检查网络数据包,或者在您的代理上启用某种调试日志记录(如果它支持)。
  • @JawadAhmadKhan 应该是requests.Session(),大写为S

标签: python python-requests tor socks torsocks


【解决方案1】:

感谢所有帮助,是的,正如 cmets 中已经提到的,代理有问题。

我变了:

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

收件人:

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

地址中的 90 到 91 有效!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多