python - 无法通过 tor ConnectionRefusedError 发出 python 请求:[WinError 10061]
问题描述
我正在尝试通过 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 - SageMaker 批量转换不断失败
- python - Tensorflow MCMC 不会演化链状态
- python - 格式化 Python Fabric 输出
- excel - Excel与索引/匹配最接近的匹配
- powershell - 如何优化跨所有域控制器的查询以找到最新的登录日期?
- security - 使用 Ory/Kratos 登录/注册 API 流程
- javascript - JavaScript:在给定索引列表的多维数组中获取元素
- flutter - Flutter 使用 path_provider 包获取外部存储目录和 MediaStore
- ios - SwiftUI - 详细视图更改为 @fetchRequest 弹出导航链接视图
- css - 尝试对标题中的两个不同单词进行悬停效果