【Python】http.client库的用法
代码:
# http.client测试,该库较底层,不常用
import http.client
conn=None
try:
    conn=http.client.HTTPSConnection("www.cnblogs.com")
    conn.request("GET","/xiandedanteng/")
    rsp=conn.getresponse()
    print("got response from "+'www.cnblogs.com/xiandedanteng/')
    print('-'*20+'Status&Reason'+'-'*20)
    print("Response.status="+str(rsp.status))
    print("Response.reason="+str(rsp.reason))
    print('-'*20+'Headers'+'-'*20)
    headers=rsp.getheaders()
    for h in headers:
        print(h)
    print('-'*20+'Message'+'-'*20)
    print(rsp.msg)
except Exception as e:
    print(e)
finally:
    if conn:
        conn.close()
输出:
C:\Users\horn1\Desktop\python\12>python httplib.py
got response from www.cnblogs.com/xiandedanteng/
--------------------Status&Reason--------------------
Response.status=200
Response.reason=OK
--------------------Headers--------------------
('Date', 'Tue, 03 Apr 2018 03:27:21 GMT')
('Content-Type', 'text/html; charset=utf-8')
(')
('Connection', 'keep-alive')
('Vary', 'Accept-Encoding')
('Cache-Control', 'private, max-age=10')
('Expires', 'Tue, 03 Apr 2018 03:27:31 GMT')
('Last-Modified', 'Tue, 03 Apr 2018 03:27:21 GMT')
('X-UA-Compatible', 'IE=10')
('X-Frame-Options', 'SAMEORIGIN')
--------------------Message--------------------
Date: Tue, 03 Apr 2018 03:27:21 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 13859
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: private, max-age=10
Expires: Tue, 03 Apr 2018 03:27:31 GMT
Last-Modified: Tue, 03 Apr 2018 03:27:21 GMT
X-UA-Compatible: IE=10
X-Frame-Options: SAMEORIGIN
2018年4月4日清晨四五点中博客园系统出现502错时,输出是:
C:\Users\horn1\Desktop\python\12>python httplib.py
got response from www.cnblogs.com/xiandedanteng/
--------------------Status&Reason--------------------
Response.status=502
Response.reason=Bad Gateway
--------------------Headers--------------------
('Date', 'Tue, 03 Apr 2018 22:31:44 GMT')
('Content-Type', 'text/html')
(')
('Connection', 'keep-alive')
--------------------Message--------------------
Date: Tue, 03 Apr 2018 22:31:44 GMT
Content-Type: text/html
Content-Length: 246
Connection: keep-alive
【Python】http.client库的用法的更多相关文章
- python爬虫---selenium库的用法
		
python爬虫---selenium库的用法 selenium是一个自动化测试工具,支持Firefox,Chrome等众多浏览器 在爬虫中的应用主要是用来解决JS渲染的问题. 1.使用前需要安装这个 ...
 - python爬虫---requests库的用法
		
requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 因为是第三方库,所以使用前需要cmd安装 pip install requests 安装完成后import一下 ...
 - Python 内置库 sys用法
		
sys模块功能众多,这边先学习几个常用的方法sys常见函数列表① sys.argv: 实现从程序外部向程序传递参数.其实sys.argv[]就是一个列表,里面的项为用户输入的参数,但是sys.argv ...
 - python的重试库tenacity用法以及类似库retry、requests实现
		
介绍 tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simpli ...
 - Python中datetime库的用法
		
datetime模块用于是date和time模块的合集,datetime有两个常量,MAXYEAR和MINYEAR,分别是9999和1. datetime模块定义了5个类,分别是 1.datetime ...
 - python的各种库的用法
		
scipy.io 用于输入和输出数据的操作,可操作matlab的.mat文件. (1)加载.mat文件的数据 import scipy.io as sci data_dir = sci.loadmat ...
 - (转)Python爬虫利器一之Requests库的用法
		
官方文档 以下内容大多来自于官方文档,本文进行了一些修改和总结.要了解更多可以参考 官方文档 安装 利用 pip 安装 $ pip install requests 或者利用 easy_install ...
 - python beautiful soup库的超详细用法
		
原文地址https://blog.csdn.net/love666666shen/article/details/77512353 参考文章https://cuiqingcai.com/1319.ht ...
 - Python爬虫Urllib库的高级用法
		
Python爬虫Urllib库的高级用法 设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Head ...
 
随机推荐
- Mac 命令行美化
			
在 mac 中使用原生的命令行工具,竟然没有 git 命令的自动补全,在 git 仓库下也看不到当前的分支名,不能忍.于是,开始一波改造. 目标:命名 Tab 自动补全:可以显示分支名: 一番 Goo ...
 - Mybatis源码分析之Mapper的创建和获取
			
Mybatis我们一般都是和Spring一起使用的,它们是怎么融合到一起的,又各自发挥了什么作用? 就拿这个Mapper来说,我们定义了一个接口,声明了一个方法,然后对应的xml写了这个sql语句, ...
 - hdu 2433  Travel(还不会)
			
Problem Description One day, Tom traveled to a country named BGM. BGM is a small country, but ...
 - 【BZOJ 2669】 2669: [cqoi2012]局部极小值 (状压DP+容斥原理)
			
2669: [cqoi2012]局部极小值 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 667 Solved: 350 Description 有一 ...
 - zend studio10 创建重复project from remote server
			
zend studio10创建重复project from remote server [本地远程到dev服务器]1.删掉已存在project隐藏文件.project .build2.如果zend10 ...
 - SpringMVC 常用注解 详解
			
SpringMVC 常用注解 详解 SpringMVC 常用注解 1.@RequestMapping 路径映射 2.@Requ ...
 - struts2漏洞S2-046修复解决方案
			
项目验收通过半年之后, 甲方找了一些网络砖家用工具扫描我司做的社保卡申领系统, 找到了struts2漏洞S2-046, 真是服了, 只知道struts2有bug, 现在才知道它漏洞. 砖家们给出了修复 ...
 - 2015 UESTC 数据结构专题D题  秋实大哥与战争 SET的妙用
			
D - 秋实大哥与战争 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...
 - SQL Server 2008 Windows身份验证改为混合模式身份验证 及修改sa密码
			
由于需要,要把SQL2008单一的Windows身份验证改为混合模式身份验证.在此做一备忘. 步骤: 1.用Windows身份验证方式进入SQL2008,在[对象资源管理器]右键击[根目录]:
 - Android中的数据存储(一):SharedPreferences                                                                                            2017-05-24 10:35             64人阅读              评论(1)              收藏
			
SharedPreferences 这是本人(菜鸟)学习android数据存储时接触的有关SharedPreferences的知识以及本人自己写的一个简单地demo,为初学者学习和使用SharedPr ...