与https代理请求
问题描述:
我正在使用python请求来使用https代理加载页面,但它不工作。相同的代码与http代理一起工作。与https代理请求
以下是我的代码:
以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请求?
我的代码中是否有错误?或者如何解决这个问题?
请帮我解决这个问题。
答
在您的第一个代码示例中,您正在使用HTTPS代理,但向HTTP站点发出请求。您应该改为r = requests.get('https://icanhazip.com', proxies=proxyDict)
。
雅这就是我昨天测试后也想到的。感谢@Rytis的帮助 –