2

I would like to send a Get request from python's httplib library, using HTTPS protocol.

I have already went through multiple answers suggesting how to do it when using http protocol, but they didn't work with https.

here's my code to defile an HTTPSConnection.

connection = httplib.HTTPSConnection(server, port=port, context=ssl_context)
connection.request("GET", path, None, headers)

I haven't included any proxy server yet in this code. If someone could tell me how to send this request with a proxy server (say : x.x.x.x:8080), it would be great help.

Update 1: I tried the following code-

import httplib
ssl_context = ssl.create_default_context()
conn = httplib.HTTPSConnection("10.136.8.10", port=8080, context=ssl_context)
conn.set_tunnel("registry-1.docker.io", port=port)
conn.request("GET", "/", None, headers) 
resp = conn.getresponse()
print resp1.status

Still not working getting error 503.

1 Answer 1

2

I haven't tried to connect to proxy through HTTPSConnection method, but it works with HTTPConnection. Any way, try to do this:

connection = httplib.HTTPSConnection(proxy_server, port=port, context=ssl_context)
connection.set_tunnel(url, port) # usually port is 443
connection.request("GET", "/", None, headers)
Sign up to request clarification or add additional context in comments.

3 Comments

It gave me this error: Tunnel connection failed: 405 Method Not Allowed
All right, So I am now testing this part on python console. I tried what the updated code, but get this error: "CannotSendRequest:"
Please check the Update1 in my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.