0

I have an elastic load balancer running on aws cloud. I have attached a HTTPS listener to it on port 443, and it is using a certificate in certificate manager. I want to send https requests from a python script to the elastic load. I can't figure out the exact api call that I should make to implement this.

1 Answer 1

0

You can make https get request to the DNS of the ELB.

To generate HTTPS request use following script quoted from this answer.

import urllib.request
r = urllib.request.urlopen('<DNS OF ELB>')
print(r.read())

If you really want to use http.client, you must call endheaders after you send the request headers:

import http.client
conn = http.client.HTTPSConnection('DNS OF ELB', 443)
conn.putrequest('GET', '/')
conn.endheaders() # <---
r = conn.getresponse()
print(r.read())

As a shortcut to putrequest/endheaders, you can also use the request method, like this:

import http.client
conn = http.client.HTTPSConnection('DOMAIN', 443)
conn.request('GET', '/') # <---
r = conn.getresponse()
print(r.read())

Update 1

For Python 2.7 You can use httplib or urllib2

If you are using httplib, HTTPS supports only if the socket module was compiled with SSL support.

For urllib2 refer this article.

Sign up to request clarification or add additional context in comments.

1 Comment

urllib.request doesn't seem to available for python2.7, I have urllib installed, but can't import urllib.requests, traceback says module doesn't exist.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.