session保持存会话
help(session())
通过help方法查看帮助文档。
使用session登录开源的OPMS系统,搭建OPMS系统,参考:https://www.cnblogs.com/canglongdao/p/12562972.html
#coding:utf-8 import requests url="http://47.98.16.11:8088/login" data={"username":"libai","password":"123456"} headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"} s=requests.Session() rs=s.post(url,data=data,headers=headers) print(rs.text) print(rs.json())
登录OPMS,新增项目,使用fiddler抓包;
python代码,参考fiddler抓包内容,填写;
#coding:utf-8 import requests url="http://47.98.106.11:8088/login" data={"username":"libai","password":"123456"} headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"} s=requests.Session() rs=s.post(url,data=data,headers=headers) print(rs.text) #新增项目 d={"name":"蛋糕1", "aliasname":"cake", "started":"2020-07-26", "ended":"2020-07-27", "desc":"good", "id":"0"} rs2=s.post("http://47.98.106.11:8088/project/add",data=d,headers=headers) print(rs2.json())
运行后,查看运行结果:
查看OPMS项目中多了一条“蛋糕1”的项目;
如上,session关联接口就是这么简单!!!