Python 基于request库的get,post,delete,封装
import requests
import json
from requests import session
import urllib3
import os
urllib3.disable_warnings()
conf_path = os.path.abspath("../api/request_param/params.json") class GetParams(object):
def __init__(self, case_name):
with open(conf_path, "r", encoding="utf-8")as fp:
data_set = json.load(fp)
current_set = data_set.get(case_name)
self.method = current_set.get("method")
self.url = current_set.get("url")
self.params = current_set.get("params")
self.data = current_set.get("data")
self.json = current_set.get("json")
self.headers = current_set.get("headers")
self.kwargs = current_set.get("kwargs")
self.session = session()
# self.session.request("post",data={username,pwd})
self.verify = False def api_request(case_name: str):
# todo case_name is the name of test_case in params.json
inst = GetParams(case_name)
with inst.session as request:
response=request.request(inst.method, inst.url, params=inst.params, data=inst.data, headers=inst.headers,
verify=inst.verify, json=inst.json) # print("测试demo返回信息为:\n%s" % json.dumps(response.json(), ensure_ascii=False, indent=2))
return json.dumps(response.json(), indent=2)
Python 基于request库的get,post,delete,封装的更多相关文章
- 基于python的request库,模拟登录csdn博客
以前爬虫用urllib2来实现,也用过scrapy的爬虫框架,这次试试requests,刚开始用,用起来确实比urllib2好,封装的更好一些,使用起来简单方便很多. 安装requests库 ...
- 在Python中用Request库模拟登录(一):字幕库(无加密,无验证码)
字幕库的登录表单如下所示,其中省去了无关紧要的内容: <form class="login-form" action="/User/login.html" ...
- 在Python中用Request库模拟登录(四):哔哩哔哩(有加密,有验证码)
!已失效! 抓包分析 获取验证码 获取加密公钥 其中hash是变化的,公钥key不变 登录 其中用户名没有被加密,密码被加密. 因为在获取公钥的时候同时返回了一个hash值,推测此hash值与密码加密 ...
- 在Python中用Request库模拟登录(三):Discuz论坛(未加密,有验证码,有隐藏验证)
以Discuz的官方站为例.直接点击网页右上角的登录按钮,会弹出一个带验证码的登录窗口.输入验证码之后,会检查验证码是否正确.然后登录.首先,通过抓包分析,这些过程浏览器和服务器交换了哪些数据. 抓包 ...
- python基于pillow库的简单图像处理
from PIL import Image from PIL import ImageFilter from PIL import ImageEnhance import matplotlib.pyp ...
- Python request库与爬虫框架
Requests库的7个主要方法 requests.request():构造一个请求,支持以下各方法的基础方法 requests.get():获取HTML网页的主要方法,对应于HTTP的GET ...
- Python网络爬虫与信息提取[request库的应用](单元一)
---恢复内容开始--- 注:学习中国大学mooc 嵩天课程 的学习笔记 request的七个主要方法 request.request() 构造一个请求用以支撑其他基本方法 request.get(u ...
- python爬虫 - Urllib库及cookie的使用
http://blog.csdn.net/pipisorry/article/details/47905781 lz提示一点,python3中urllib包括了py2中的urllib+urllib2. ...
- 爬虫request库规则与实例
Request库的7个主要方法: requests.request(method,url,**kwargs) method:请求方式,对应get/put/post等7种: r = reques ...
随机推荐
- POJ 1258(最小生成树+知识)
用kruskal算法,利用w[i]给r[i]间接排序,从而r[i]可以按照边大小保存序号,同时要判断是否在一个集合里面 #include <cstdio> #include <ios ...
- K:逆波兰算法
相关介绍: 一种求解字符串形式的表达式的结果的算法,该算法在求解时,需要先将我们平日里习惯上使用的中序表达式的模式转化为等价的后序(后缀)表达式的模式,之后再通过求解出该后序(后缀)表达式的结果而得 ...
- Q:关于栈的常见问题
对于栈,一个常见的问题是:给定一个序列a0,a1,a2,a3...an依次顺序入栈,在元素顺序入栈的过程中,栈中任意一个元素可以选择是否出栈,则其共有几种出栈的可能,给定的出栈序列中,哪种是不可能的 ...
- react项目 路径优化
- Flume -- Transfer one type of source to another type
Source within Flume is a kind of Server for outside client. Sink within Flume is a kind of client fo ...
- JAVA - JDK 1.8 API 帮助文档-中文版
JAVA - JDK 1.8 API 帮助文档-中文版 百度云链接: https://pan.baidu.com/s/1_7FFadw1a6J0qTfx2FzqPQ 密码: 41n4
- QTreeView/QTableView中利用QStandardItem实现复选框三种形态变化
https://www.techieliang.com/2017/12/729/ 原文地址 using_checkbox_item.h /** * @file using_checkbox_item. ...
- CentOS随笔 - 2.CentOS7安装ftp支持(vsftpd)
前言 转帖请注明出处: http://www.cnblogs.com/Troy-Lv5/ 在前一篇文章中介绍了在虚拟机中安装CentOS7, 接下来就要进行配置了, 第一个就是安装ftp支持. 要不然 ...
- kettle 合并记录
转自: http://blog.itpub.net/post/37422/464323 看到别人的脚本用到 合并记录 步骤,学下下. 该步骤用于将两个不同来源的数据合并,这两个来源的数据分别为旧数据和 ...
- Linux中如何安装loadgenerator
/* 1. 到官方网站到HP官网下载Load Generator 安装文件 _Load_Generator_11.00_T7330-15010.iso或者其它网站下载loadrunner-11-loa ...