简体   繁体   中英

Why does this proxy require authentication when used from curl but not from python requests?

I'm using https://github.com/abhinavsingh/proxy.py , setting it up with basic auth like so:

proxy --basic-auth "user:pass"

When I use it with curl, it requires proxy auth as expected:

curl -I -x localhost:8899 http://example.com  => 407
curl -I -x user:pass@localhost:8899 http://example.com => 200

But when I use it from Python, I can access it without providing any auth:

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) 

I get a 200. Am I missing something?

This looks like a bug in proxy.py . It appears to be triggered by the fact that requests makes an HTTP/1.0 request with no request headers. You can trigger the same issue yourself:

$ 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

Unlike requests , curl always sends request headers, even when using --proxy1.0 , so it's not possible to trigger the same behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM