代码:

# 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库的用法的更多相关文章

  1. python爬虫---selenium库的用法

    python爬虫---selenium库的用法 selenium是一个自动化测试工具,支持Firefox,Chrome等众多浏览器 在爬虫中的应用主要是用来解决JS渲染的问题. 1.使用前需要安装这个 ...

  2. python爬虫---requests库的用法

    requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 因为是第三方库,所以使用前需要cmd安装 pip install requests 安装完成后import一下 ...

  3. Python 内置库 sys用法

    sys模块功能众多,这边先学习几个常用的方法sys常见函数列表① sys.argv: 实现从程序外部向程序传递参数.其实sys.argv[]就是一个列表,里面的项为用户输入的参数,但是sys.argv ...

  4. python的重试库tenacity用法以及类似库retry、requests实现

    介绍 tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simpli ...

  5. Python中datetime库的用法

    datetime模块用于是date和time模块的合集,datetime有两个常量,MAXYEAR和MINYEAR,分别是9999和1. datetime模块定义了5个类,分别是 1.datetime ...

  6. python的各种库的用法

    scipy.io 用于输入和输出数据的操作,可操作matlab的.mat文件. (1)加载.mat文件的数据 import scipy.io as sci data_dir = sci.loadmat ...

  7. (转)Python爬虫利器一之Requests库的用法

    官方文档 以下内容大多来自于官方文档,本文进行了一些修改和总结.要了解更多可以参考 官方文档 安装 利用 pip 安装 $ pip install requests 或者利用 easy_install ...

  8. python beautiful soup库的超详细用法

    原文地址https://blog.csdn.net/love666666shen/article/details/77512353 参考文章https://cuiqingcai.com/1319.ht ...

  9. Python爬虫Urllib库的高级用法

    Python爬虫Urllib库的高级用法 设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Head ...

随机推荐

  1. shell中的cat和文件分界符(<<EOF) (转)

    原文地址: http://blog.csdn.net/mosesmo1989/article/details/51123257 在shell中,文件分界符(通常写成EOF,你也可以写成FOE或者其他任 ...

  2. C和指针之学习笔记(4)

    第9章 字符串 字符串的输入与输出 int  ch;  char strings[80];  FILE *input; (1)scanf(“%c”,&ch);   printf(“%c \n” ...

  3. CodeForces - 1009E Intercity Travelling

    题面在这里! 可以发现全是求和,直接拆开算贡献就好了 #include<bits/stdc++.h> #define ll long long using namespace std; c ...

  4. Python字典树实现

    class Trie: # word_end = -1 def __init__(self): """ Initialize your data structure he ...

  5. c++string函数详解

    string,一个极为好用了函数,学好了这些函数,在模拟以及字符串问题上,回节省很多很多的写代码时间,代码复杂度以及错误率,那么这一类函数都有那些功能呢?我们来逐一介绍(让你大吃一惊,还有这种操作?) ...

  6. git -- git clone

    git clone 命令参数: usage: git clone [options] [--] <repo> [<dir>] -v, --verbose be more ver ...

  7. 《C# to IL》第一章 IL入门

    我们用C#.VB.NET语言编写的代码最终都会被编译成程序集或IL.因此用VB.NET编写的代码可以在C#中修改,随后在COBOL中使用.因此,理解IL是非常有必要的. 一旦熟悉了IL,理解.NET技 ...

  8. C# winform 禁止窗体移动

    #region 禁止窗体移动 public const int WM_SYSCOMMAND = 0x112; public const int SC_MOVE = 0xF012; protected ...

  9. HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)

    Building Fence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  10. Lower dc/dc-converter ripple by using optimum capacitor hookup

    Low-ripple-voltage positive-to-negative dc/dc converters find use in many of today's high- frequency ...