Python3处理HTTP请求的实例

yipeiwu_com5年前Python基础

Python3处理HTTP请求的包:http.client,urllib,urllib3,requests

其中,http 比较 low-level,一般不直接使用

urllib更 high-level一点,属于标准库。urllib3跟urllib类似,拥有一些重要特性而且易于使用,但是属于扩展库,需要安装

requests 基于urllib3 ,也不是标准库,但是使用非常方便

个人感觉,如果非要用标准库,就使用urllib。如果没有限制,就用requests

# import http.client
# http_client = http.client.HTTPConnection('localhost',8080,timeout=10)
# http_client.request('get','/jenkins/api/json?pretty=true')
# response = http_client.getresponse()
# print(response.status)
# print(response.read())
# import urllib.request
# response = urllib.request.urlopen('http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status)
# print(response.read())
# import urllib3
# response = urllib3.PoolManager().request('get','http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status)
# import requests
# response = requests.get('http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status_code)
# print(response.text)
# print(response.json())
# print(response.reason)
import requests
from requests.auth import HTTPBasicAuth
response = requests.post('http://localhost:8080/jenkins/job/check_python_version/build',auth=('admin','wangmin'))
print (response.status_code)
print (response.reason)
print(response.headers)

jenkins系统管理=》Configure Global Security,取消勾选“防止跨站点请求伪造”

以上这篇Python3处理HTTP请求的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python3.6、opencv安装环境搭建过程(图文教程)

python3.6、opencv安装环境搭建过程(图文教程)

我需要使用tesseract-OCR的模块,vs的配置有点麻烦,所以采用py的环境,搭建。 1.在python.org网站下载python3.6版本 我下载的3.6.8的python的...

Python一行代码解决矩阵旋转的问题

今天刷《剑指offer》的时候碰到这样一道题: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10...

转换科学计数法的数值字符串为decimal类型的方法

在操作数据库时,需要将字符串转换成decimal类型。 代码如下: select cast('0.12' as decimal(18,2)); select convert(dec...

使用 tf.nn.dynamic_rnn 展开时间维度方式

使用 tf.nn.dynamic_rnn 展开时间维度方式

对于单个的 RNNCell , 使用色的 call 函数进行运算时 ,只是在序列时间上前进了一步 。如使用 x1、 ho 得到此h1, 通过 x2 、 h1 得到 h2 ...

Python Sql数据库增删改查操作简单封装

本文实例为大家分享了如何利用Python对数据库的增删改查进行简单的封装,供大家参考,具体内容如下 1.insert     import...