Python介面自動化(六) session關聯介面
阿新 • • 發佈:2020-07-26
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關聯介面就是這麼簡單!!!