Python technology articles-httpClient library connects to the server to send a request analysis response example demonstration, No module named'httplib' problem solution

The new python has been changed from httplib package to http.client .
So if you also introduce the httplib library, an error will be reported:ModuleNotFoundError: No module named 'httplib'

import http.client

httpClient = http.client.HTTPConnection('10.10.xx.xx',5554)
# 发送请求,直接用参数/,相当于直接访问ip+端口号
httpClient.request('GET','/')
# 获取请求
response = httpClient.getresponse()
# 分解response回应消息
print("status:"+str(response.status))
# print(response.reason)
# print(response.read())
print('-'*5+'Headers'+'-'*5)
print(response.getheaders())
print('-'*5+'Message'+'-'*5)
print(response.msg)

The results after executing the code are as follows:

status:200
-----Headers-----
[('Accept-Ranges', 'bytes'), ('ETag', 'W/"93-1589209308000"'), ('Last-Modified',
 'Mon, 11 May 2020 15:01:48 GMT'), ('Content-Type', 'text/html'), ('Content-Leng
th', '93'), ('Date', 'Thu, 06 Aug 2020 13:23:28 GMT'), ('Server', 'server')]
-----Message-----
Accept-Ranges: bytes
ETag: W/"93-1589209308000"
Last-Modified: Mon, 11 May 2020 15:01:48 GMT
Content-Type: text/html
Content-Length: 93
Date: Thu, 06 Aug 2020 13:23:28 GMT
Server: server

Like it if you like it ❤!

Guess you like

Origin blog.csdn.net/qq_38161040/article/details/107849745