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实现连接SQLite数据库的方法
Aug 23 Python
Python3 socket同步通信简单示例
Jun 07 Python
python微信跳一跳系列之棋子定位像素遍历
Feb 26 Python
python 将列表中的字符串连接成一个长路径的方法
Oct 23 Python
在matplotlib的图中设置中文标签的方法
Dec 13 Python
Python获取网段内ping通IP的方法
Jan 31 Python
Python图像处理模块ndimage用法实例分析
Sep 05 Python
opencv3/C++图像像素操作详解
Dec 10 Python
win10安装tesserocr配置 Python使用tesserocr识别字母数字验证码
Jan 16 Python
Python多线程获取返回值代码实例
Feb 17 Python
python爬虫工具例举说明
Nov 30 Python
Django与AJAX实现网页动态数据显示的示例代码
Feb 24 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
目录,文件操作详谈―PHP
2006/11/25 PHP
PHP学习散记_编码(json_encode 中文不显示)
2011/11/10 PHP
phpQuery占用内存过多的处理方法
2013/11/13 PHP
PHP 面向对象程序设计(oop)学习笔记(三) - 单例模式和工厂模式
2014/06/12 PHP
php相对当前文件include其它文件的方法
2015/03/13 PHP
ThinkPHP框架里隐藏index.php
2016/04/12 PHP
浅析php中array_map和array_walk的使用对比
2016/11/20 PHP
PHP实现的多维数组排序算法分析
2018/02/10 PHP
laravel5.6实现数值转换
2019/10/23 PHP
Dojo 学习笔记入门篇 First Dojo Example
2009/11/15 Javascript
iframe异步加载实现点击左边菜单加载右边内容实例讲解
2013/03/04 Javascript
onkeyup,onkeydown和onkeypress的区别介绍
2013/10/21 Javascript
JavaScript 异常处理 详解
2015/02/06 Javascript
node.js下LDAP查询实例分享
2015/09/30 Javascript
vue组件实现文字居中对齐的方法
2017/08/23 Javascript
详解50行代码,Node爬虫练手项目
2019/04/22 Javascript
Bootstrap FileInput实现图片上传功能
2021/01/28 Javascript
高效使用Python字典的清单
2018/04/04 Python
python实现反转部分单向链表
2018/09/27 Python
十分钟搞定pandas(入门教程)
2019/06/21 Python
Python timer定时器两种常用方法解析
2020/01/20 Python
Python中Yield的基本用法
2020/10/18 Python
中东奢侈品购物网站:Ounass
2020/09/02 全球购物
银行毕业实习自我鉴定
2013/09/19 职场文书
新颖的化妆品活动方案
2014/08/21 职场文书
出生医学证明书
2014/09/15 职场文书
国防教育标语
2014/10/08 职场文书
2014年护士个人工作总结
2014/11/11 职场文书
承诺函格式模板
2015/01/21 职场文书
2015年度残疾人工作总结
2015/05/14 职场文书
python绘图subplots函数使用模板的示例代码
2021/04/30 Python
Pytorch数据读取之Dataset和DataLoader知识总结
2021/05/23 Python
MySQL如何解决幻读问题
2021/08/07 MySQL
CentOS8.4安装Redis6.2.6的详细过程
2021/11/20 Redis
MySQL创建管理子分区
2022/04/13 MySQL
SQL Server Agent 服务无法启动
2022/04/20 SQL Server