Python3处理HTTP请求的实例


Posted in Python onMay 10, 2018

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请求的实例

以上这篇Python3处理HTTP请求的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python3简单实现微信爬虫
Apr 09 Python
Python解析最简单的验证码
Jan 07 Python
十条建议帮你提高Python编程效率
Feb 16 Python
举例讲解Python中metaclass元类的创建与使用
Jun 30 Python
Python实现自动添加脚本头信息的示例代码
Sep 02 Python
利用python将xml文件解析成html文件的实现方法
Dec 22 Python
Python socket模块方法实现详解
Nov 05 Python
Python CSS选择器爬取京东网商品信息过程解析
Jun 01 Python
2021年的Python 时间轴和即将推出的功能详解
Jul 27 Python
Python用K-means聚类算法进行客户分群的实现
Aug 23 Python
Python虚拟环境的创建和使用详解
Sep 07 Python
使用python+pygame开发消消乐游戏附完整源码
Jun 10 Python
python字符串与url编码的转换实例
May 10 #Python
Python中的单继承与多继承实例分析
May 10 #Python
python3处理含有中文的url方法
May 10 #Python
Python异常处理操作实例详解
May 10 #Python
解决python3 网络请求路径包含中文的问题
May 10 #Python
Python之文字转图片方法
May 10 #Python
Python实现查看系统启动项功能示例
May 10 #Python
You might like
ASP知识讲座四
2006/10/09 PHP
thinkphp模板用法和内容输出实例
2014/11/28 PHP
php统计数组元素个数的方法
2015/07/02 PHP
PHP数据库连接mysql与mysqli对比分析
2016/01/04 PHP
利用php + Laravel如何实现部署自动化详解
2017/10/11 PHP
php处理多图上传压缩代码功能
2018/06/13 PHP
js全选实现和判断是否有复选框选中的方法
2015/02/17 Javascript
js基础之DOM中document对象的常用属性方法详解
2016/10/28 Javascript
微信小程序 PHP后端form表单提交实例详解
2017/01/12 Javascript
让网站自动生成章节目录索引的多个js代码
2018/01/07 Javascript
解决Layui数据表格中checkbox位置不居中的方法
2018/08/15 Javascript
深入解析Vue源码实例挂载与编译流程实现思路详解
2019/05/05 Javascript
使用VueCli3+TypeScript+Vuex一步步构建todoList的方法
2019/07/25 Javascript
layui 根据后台数据动态创建下拉框并同时默认选中的实例
2019/09/02 Javascript
实例讲解JavaScript 计时事件
2020/07/04 Javascript
浅谈vue中resetFields()使用注意事项
2020/08/12 Javascript
[01:01:24]DOTA2上海特级锦标赛A组败者赛 EHOME VS CDEC第三局
2016/02/25 DOTA
python实现的简单文本类游戏实例
2015/04/28 Python
Python爬虫实现模拟点击动态页面
2020/03/05 Python
matplotlib 画动态图以及plt.ion()和plt.ioff()的使用详解
2021/01/05 Python
python palywright库基本使用
2021/01/21 Python
SEPHORA新西兰官方网站:购买化妆品和护肤品
2016/12/02 全球购物
Argos官网:英国家喻户晓的百货零售连锁商
2017/04/03 全球购物
中国双语服务优势的在线购票及活动平台:247tickets
2018/10/26 全球购物
Luxplus荷兰:以会员价购买美容产品等,独家优惠
2019/08/30 全球购物
办公室文秘自我评价
2013/09/21 职场文书
宿舍使用违章电器检讨书
2014/01/12 职场文书
程序员求职信
2014/04/16 职场文书
法学求职信
2014/06/22 职场文书
人代会标语
2014/06/30 职场文书
社区文明创建工作总结2015
2015/04/21 职场文书
工厂员工辞职信范文
2015/05/12 职场文书
天河观后感
2015/06/11 职场文书
如何书写民事调解协议书?
2019/06/25 职场文书
python实现高效的遗传算法
2021/04/07 Python
Python爬取某拍短视频
2021/06/11 Python