【问题标题】:requests with https proxy使用 https 代理的请求
【发布时间】:2017-06-27 12:57:08
【问题描述】:

我正在使用 python 请求使用 https 代理加载页面,但它不起作用。相同的代码适用于 http 代理。

以下是我的代码:

使用 https 代理

import requests
proxyDict = {'https': 'https://xxx.xxx.xxx.xxx:xx'}
r = requests.get('http://icanhazip.com', proxies=proxyDict)
print(r)
print(r.content)

输出:

响应 [200]

xxx.xxx.xxx.xxx - ip 用于我的服务器而不是代理服务器

带有http代理

import requests
proxyDict = {'http': 'http://xxx.xxx.xxx.xxx:xx'}
r = requests.get('http://icanhazip.com', proxies=proxyDict)
print(r)
print(r.content)

输出:

响应 [200]

xxx.xxx.xxx.xxx - ip 用于代理服务器

如何使用 https 代理服务器与 python 请求

我的代码有错误吗?或者如何解决这个问题?

请帮我解决这个问题。

【问题讨论】:

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


    【解决方案1】:

    在您的第一个代码示例中,您使用 HTTPS 代理但向 HTTP 站点发出请求。你应该改用r = requests.get('https://icanhazip.com', proxies=proxyDict)

    【讨论】:

    • 是的,这也是我昨天测试后发现的。感谢@Rytis 的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2015-10-16
    • 2023-03-22
    • 1970-01-01
    • 2022-08-02
    • 2017-07-28
    相关资源
    最近更新 更多