python - 无法通过 tor ConnectionRefusedError : [WinError 10061] 发出 python 请求

标签 python python-requests tor socks torsocks

我尝试通过 Tor 使用 python 请求发出请求,但收到错误“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。

最佳答案

感谢您的所有帮助,是的,正如评论中已经提到的,代理出现了问题。

我改变了:

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 就成功了!

关于python - 无法通过 tor ConnectionRefusedError : [WinError 10061] 发出 python 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59551276/

相关文章:

python - 在 ubuntu 16.04 上安装 pip

python - 在 Matplotlib 中使用子图时如何控制颜色条位置

ssl - 无法确定哪个包更新导致 python 请求包的 CA 证书位置发生变化

tor -/var/lib/tor 无法读取 : Permission denied or Couldn't create private data directory

c# - 如何在 C# 中使用 Tor 控制协议(protocol)?

python - 包含 python 对象的测试

Python - selenium 和 lxml 中的相同 xpath 不同结果

python - 有没有办法通过只调用类的名称来调用函数?

python - 模块 'requests' 未通过登录

c# - Tor NEWNYM 不使用 C#