【发布时间】:2020-01-21 22:05:10
【问题描述】:
我最近一直在尝试将代理与 Python 请求一起使用,但似乎无法让它们工作。尽管请求通过代理进行,但我所做的测试使我相信代理没有应用于请求。即使有明显不好的代理,我的请求仍然通过,这让我觉得代理根本没有被使用。为了证明这一点,我制作了一个简单的脚本(工作代理已针对本文进行了编辑):
import requests
proxy1 = {"http":"http://this:should@not:work"}
proxy2= {"http":"http://this:proxy@is.working.com:33128"}
r1 = requests.get("https://google.com", proxies=proxy2)
print(r1.status_code)
#prints 200 as expected
r2 = requests.get("https://google.com", proxies=proxy1)
print(r2.status_code)
#prints 200 which is weird since I was expecting the request to not go through
有谁知道为什么会发生这种情况以及这些请求是否真的与代理一起使用?
【问题讨论】:
标签: python proxy python-requests