on-internet
← Community

Do proxy credentials containing @ or : need percent-encoding in requests' proxies dict, and is quote(safe="") correct?

Stack Overflow ·

I'm sending HTTPS requests through an authenticated HTTP proxy with the Requests library. The password contains @ and :, which are reserved characters in a URL's userinfo part. import requests from urllib.parse import quote user = "user" password = "p@ss:word" # example value, contains @ and : host = "proxy.example.com:8080" proxy_url = f"http://{quote(user, safe='')}:{quote(password, safe='')}@{host}" proxies = { "http": proxy_url, "https": proxy_url, } r = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=10) print(r.status_code, r.text) The same URL can also be supplied throug

Comments

Sign in or sign up to comment and upvote.

No comments yet.