gpt4 book ai didi

python - 使用 https 代理请求

转载 作者:太空宇宙 更新时间:2023-11-04 02:56:41 26 4
gpt4 key购买 nike

我正在使用 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)

Output:

Response [200]

xxx.xxx.xxx.xxx - the ip is for my server and not the proxy server

使用http代理

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

Output:

Response [200]

xxx.xxx.xxx.xxx - the ip is for proxy server

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

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

请帮我解决这个问题。

最佳答案

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

关于python - 使用 https 代理请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42138004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com