http.client.ResponseNotReady: Idle

Viewed 2277

I'm trying to learn how to code with http.client but a simple code ends in this error and I don't know what to do.

import http.client

conn=http.client.HTTPSConnection('www.google.com')
res=conn.getresponse()
print(res.status,res.reason)

and the error it gives me is:

Traceback (most recent call last): File "C:/Users/A/PycharmProjects/untitled/testung.py", line 9, in res=conn.getresponse() File "C:\Users\A\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1312, in getresponse raise ResponseNotReady(self.__state) http.client.ResponseNotReady: Idle –

1 Answers

From python official documentation:

HTTPConnection.getresponse() Should be called after a request is sent to get the response from the server. Returns an HTTPResponse instance.

Source

So changing your code to this

import http.client

conn=http.client.HTTPSConnection('www.google.com')
conn.request("GET", "/")
res=conn.getresponse()
print(conn)

Outputs

<http.client.HTTPSConnection object at 0x01DFEEB0>
Related