无法通过连接拒绝错误发出 python 请求:[WinError 10061] [英] Unable to make python requests over tor ConnectionRefusedError: [WinError 10061]

查看:44
本文介绍了无法通过连接拒绝错误发出 python 请求:[WinError 10061]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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".

这是我使用的代码:

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.

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.

推荐答案

感谢大家的帮助,是的,正如评论中已经提到的,代理出了点问题.

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

我改变了:

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 并且有效!

90 to 91 in address and it worked !

这篇关于无法通过连接拒绝错误发出 python 请求:[WinError 10061]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆