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
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
endheadersafter 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 therequestmethod, 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.
1 Comment
Piyush Divyanakar
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.