![](/img/trans.png)
[英]Making HTTP requests via Python Requests module not working via proxy where curl does? Why?
[英]Why does this proxy require authentication when used from curl but not from python requests?
我正在使用https://github.com/abhinavsingh/proxy.py ,使用基本身份验证进行设置,如下所示:
proxy --basic-auth "user:pass"
当我将它与 curl 一起使用时,它需要代理身份验证,如预期:
curl -I -x localhost:8899 http://example.com => 407
curl -I -x user:pass@localhost:8899 http://example.com => 200
但是当我从 Python 使用它时,我可以在不提供任何身份验证的情况下访问它:
import requests
proxies = {
"http": "http://127.0.0.1:8899",
"https": "http://127.0.0.1:8899"
}
response = requests.get("https://www.example.com", proxies=proxies)
print(response.status_code)
我得到了 200。我错过了什么吗?
这看起来像proxy.py
中的错误。 它似乎是由requests
发出没有请求标头的HTTP/1.0
请求这一事实触发的。 您可以自己触发相同的问题:
$ telnet localhost 8899
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CONNECT www.example.com:80 HTTP/1.0
HTTP/1.1 200 Connection established
与requests
不同, curl
始终发送请求标头,即使使用--proxy1.0
如此,因此不可能触发相同的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.