Last active
February 22, 2023 12:21
-
-
Save beugley/13dd4cba88a19169bcb0 to your computer and use it in GitHub Desktop.
Python: use httplib with proxy authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urlparse | |
import httplib | |
import base64 | |
proxy_uri = "http://user:password@proxy_host:proxy_port" | |
host = 'www.google.com' | |
port = 443 | |
url = urlparse.urlparse(proxy_uri) | |
conn = httplib.HTTPSConnection(url.hostname, url.port) | |
headers = {} | |
if url.username and url.password: | |
auth = '%s:%s' % (url.username, url.password) | |
headers['Proxy-Authorization'] = 'Basic ' + base64.b64encode(auth) | |
conn.set_tunnel(host, port, headers) | |
conn.request("GET", "/") | |
response = conn.getresponse() | |
print response.status, response.reason | |
output = response.read() |
It's still working when I pass the wrong URL password. Shouldn't it give an Authentication exception?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, when I run the conn.request(), it times out. This shouldn't be happening. Anyone ever encountered this?