【问题标题】:Python3 Requests not using passed-in proxyPython3请求不使用传入的代理
【发布时间】:2018-04-07 16:55:55
【问题描述】:

Requests 没有使用我传递给它的代理。我正在使用的 url 上的站点显示请求来自哪个 ip - 它始终是我的 ip 而不是代理 ip。我从 sslproxies.org 获取我的代理 ip,这些代理 ip 应该是匿名的。

    url = 'http://www.lagado.com/proxy-test'
    proxies = {'http': 'x.x.x.x:xxxx'}
    headers = {'User-Agent': 'Mozilla...etc'}

    res = requests.get(url, proxies=proxies, headers=headers)

是否需要使用某些标头或需要配置其他内容,以便对服务器隐藏我的 ip?

【问题讨论】:

    标签: python python-3.x proxy network-programming python-requests


    【解决方案1】:

    docs 状态

    代理 URL 必须包含方案。

    其中方案是scheme://hostname。因此,您应该在代理 URL 中添加“http://”或“socks5://”,具体取决于您使用的协议。

    【讨论】:

    • 你把我引向了正确的方向。 Requests 的行为仍然很有趣。当我使用“https”作为密钥时,它不会通过代理(即使代理协议应该是 https)。当我使用“http”时,一切正常——即使我在 URL 中省略了 scheme://。感谢您的回复,非常有帮助!
    猜你喜欢
    • 2015-10-24
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    相关资源
    最近更新 更多