I would like to connect to a site via HTTPS in Python 3.2.
I tried
conn = http.client.HTTPSConnection(urlStr, 8443)
conn.putrequest('GET', '/')
response = conn.getresponse()
print(response.read())
but I get
http.client.ResponseNotReady: Request-started
Anyone know what the problem is?
asked Mar 23, 2012 at 12:27
user1190650
3,4456 gold badges29 silver badges34 bronze badges
2 Answers 2
First of all, if you just want to download something and don't want any special HTTP requests, you should use urllib.request instead of http.client.
import urllib.request
r = urllib.request.urlopen('https://paypal.com/')
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('paypal.com', 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('paypal.com', 443)
conn.request('GET', '/') # <---
r = conn.getresponse()
print(r.read())
answered Mar 23, 2012 at 12:36
phihag
289k75 gold badges475 silver badges489 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
instead of putrequest, you can use request
conn.request('GET', '/')
resp = conn.getresponse()
print(resp.read())
answered Mar 23, 2012 at 12:49
Corey Goldberg
61.6k30 gold badges135 silver badges148 bronze badges
Comments
lang-py