Python 技术篇-httpClient库连接服务器发送请求解析响应实例演示,No module named ‘httplib‘问题解决方法
发布日期:2021-06-30 16:45:13 浏览次数:2 分类:技术文章

本文共 969 字,大约阅读时间需要 3 分钟。

新的 python 已经由 httplib 包变成了 http.client

所以如果还引入 httplib 库就会报错:ModuleNotFoundError: No module named 'httplib'

import http.clienthttpClient = 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)

执行代码后结果如下:

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-Length', '93'), ('Date', 'Thu, 06 Aug 2020 13:23:28 GMT'), ('Server', 'server')]-----Message-----Accept-Ranges: bytesETag: W/"93-1589209308000"Last-Modified: Mon, 11 May 2020 15:01:48 GMTContent-Type: text/htmlContent-Length: 93Date: Thu, 06 Aug 2020 13:23:28 GMTServer: server

喜欢的点个赞❤吧!

转载地址:https://lanzao.blog.csdn.net/article/details/107849745 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Python 技术篇-通过进程名称、PID杀死windows进程的两种方法,获取当前运行程序的pid
下一篇:Python 技术篇-pip安装提示:‘pip‘ 不是内部或外部命令,也不是可运行的程序或批处理文件,问题解决方法

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月14日 01时33分49秒