gpt4 book ai didi

python-3.x - http.client.ResponseNotReady : Idle

转载 作者:行者123 更新时间:2023-12-04 10:29:35 29 4
gpt4 key购买 nike

我正在尝试学习如何使用 http.client 进行编码,但一个简单的代码以这个错误结束,我不知道该怎么做。

import http.client

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

它给我的错误是:

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 –

最佳答案

来自python官方文档:

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

Source

所以把你的代码改成这样

import http.client

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

输出

<http.client.HTTPSConnection object at 0x01DFEEB0>

关于python-3.x - http.client.ResponseNotReady : Idle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60473649/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com