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 相关文章推荐
python实现sublime3的less编译插件示例
Apr 27 Python
Python入门篇之文件
Oct 20 Python
python生成词云的实现方法(推荐)
Jun 13 Python
Python字符编码与函数的基本使用方法
Sep 30 Python
Python配置mysql的教程(推荐)
Oct 13 Python
python机器学习之神经网络(三)
Dec 20 Python
安装python时MySQLdb报错的问题描述及解决方法
Mar 20 Python
对python for 文件指定行读写操作详解
Dec 29 Python
python画图——实现在图上标注上具体数值的方法
Jul 08 Python
Jupyter 无法下载文件夹如何实现曲线救国
Apr 22 Python
Python实现CAN报文转换工具教程
May 05 Python
python 多线程死锁问题的解决方案
Aug 25 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
文件系统基本操作类
2006/11/23 PHP
php正则表达式获取内容所有链接
2015/07/24 PHP
PHP闭包函数详解
2016/02/13 PHP
PHP receiveMail实现收邮件功能
2018/04/25 PHP
PHP使用curl_multi_select解决curl_multi网页假死问题的方法
2018/08/15 PHP
JS判断文本框内容改变事件的简单实例
2014/03/07 Javascript
javascript实现添加附件功能的方法
2015/11/18 Javascript
javascript移动开发中touch触摸事件详解
2016/03/18 Javascript
js仿搜狐视频记录片列表展示效果
2020/05/30 Javascript
select下拉框插件jquery.editable-select详解
2017/01/22 Javascript
详解webpack进阶之插件篇
2017/07/06 Javascript
es6 字符串String的扩展(实例讲解)
2017/08/03 Javascript
JS对象序列化成json数据和json数据转化为JS对象的代码
2017/08/23 Javascript
Vue父子模版传值及组件传值的三种方法
2017/11/27 Javascript
[00:32]2018DOTA2亚洲邀请赛Mineski出场
2018/04/04 DOTA
Python实现方便使用的级联进度信息实例
2015/05/05 Python
在Django框架中伪造捕捉到的URLconf值的方法
2015/07/18 Python
Python简单实现TCP包发送十六进制数据的方法
2016/04/16 Python
利用 python 对目录下的文件进行过滤删除
2017/12/27 Python
Python网络编程之TCP与UDP协议套接字用法示例
2018/02/02 Python
python实现自动获取IP并发送到邮箱
2018/12/26 Python
python制作图片缩略图
2019/04/30 Python
python async with和async for的使用
2019/06/20 Python
在django中,关于session的通用设置方法
2019/08/06 Python
python使用自定义钉钉机器人的示例代码
2020/06/24 Python
Win10下配置tensorflow-gpu的详细教程(无VS2015/2017)
2020/07/14 Python
Python加载数据的5种不同方式(收藏)
2020/11/13 Python
马来西亚最大的电器网站:Senheng
2017/10/13 全球购物
英国和爱尔兰的自炊式豪华度假小屋:Rural Retreats
2018/06/08 全球购物
卫校中专生的自我评价
2014/01/15 职场文书
大学生旅游业创业计划书
2014/01/29 职场文书
远程研修随笔感言
2014/02/10 职场文书
理想演讲稿范文
2014/05/21 职场文书
农村文化活动总结
2014/08/28 职场文书
党支部意见范文
2015/06/02 职场文书
情况说明书怎么写
2015/10/08 职场文书