【问题标题】:Make a python 3 request using proxy使用代理发出 python 3 请求
【发布时间】:2018-12-04 14:00:48
【问题描述】:

我想使用 python 3 发出匿名网络请求。

我尝试了一些建议,例如:Make requests using Python over Tor

我已经设法使用这个 sn-p 获得了一个假 ip:

安装

pip 安装请求请求[socks]

基本用法

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:9150',
                       'https': 'socks5://127.0.0.1:9150'}
    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)

但这仅适用于端口 9150 并且当 Tor 网络浏览器工作时。 我想在没有 Tor 浏览器的情况下发出请求,因为我想 Dockerize 整个事情。

我已经阅读了有关 Socks5 的信息,如您所见,我已经安装了它,但是当我在同一个 sn-p 上的端口 9050 上发出请求时,我得到:

requests.exceptions.ConnectionError: SOCKSHTTPConnectionPool(host='httpbin.org', port=80): 最大重试次数 超出 url: /ip (由 NewConnectionError(': 建立新连接失败: [WinError 10061] 无法建立连接,因为目标机器主动 拒绝了',))

我该如何解决?

谢谢!

【问题讨论】:

标签: python python-3.x python-requests tor socks


【解决方案1】:

10061 是“连接被拒绝”

这意味着在您尝试连接的端口上没有任何监听,没有服务启动并运行(没有开放端口)或目标 IP 上的防火墙阻止它

您可以使用 telnet 测试该端口

telnet `IP` `PORT`

还要检查 Windows 上的这个端口问题:here

【讨论】:

  • 解决了!您提供的链接中的说明没有帮助。但我想如果我双击 tor.exe 它开始收听.. 谢谢!
  • 没有运行 Tor 意味着该端口上没有任何东西在监听(没有打开的端口)
【解决方案2】:

我也遇到了这个问题,在我的情况下,我的 tor 服务没有运行,实际上我使用的是透明代理 kalitorify,每当我使用它时,我都无法使用普通网站,例如谷歌搜索或类似的,所以要使用这些网站,我关闭了我的 kalitorify 服务,这也关闭了你的 tor 服务

所以如果你也在使用它,那么也要检查一次

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-28
    • 2023-04-06
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多