通过TOR提升连接

2024-04-19 06:16:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法通过TOR连接到Internet。我已经按照thisyoutube视频中的所有说明进行了操作,但仍有错误:

Connected to Tor # printed string

Traceback (most recent call last):
  ....
  ....

  File "C:\Python27\lib\httplib.py", line 787, in connect
    self.timeout, self.source_address)
  File "C:\Python27\lib\socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it  

我附上代码:

^{pr2}$

我很困惑,因为据说我必须从这个页面下载TOR:https://www.torproject.org/-当我安装它时,它工作了-我可以启动torbrowser并浏览。但这家伙有一个我没有的维达利亚控制面板。在

问题出在哪里?在


Tags: inpyself视频lib错误linesocket
1条回答
网友
1楼 · 发布于 2024-04-19 06:16:51

与其直接使用套接字,不如使用requesocks库通过本地运行的SOCKS代理路由HTTP请求。在

从那里,配置您的Session对象以使用http的本地代理,然后发出任意请求:

session = requests.session()
session.proxies = {'http': 'socks5://127.0.0.1:9050',
                   'https': 'socks5://127.0.0.1:9050'}
resp = session.get('https://api.github.com', auth=('user', 'pass'))
print(resp.status_code)
print(resp.text)

相关问题 更多 >