1.yaml
logindata: name: 'ct0356' psw: '111111'
2.读取yaml文件
# 读取yaml文件 并获得字典类的返回 import yaml def get_yaml(yaml_path): with open(yaml_path,encoding='utf-8') as fo: yaml_data = yaml.safe_load(fo.read()) return yaml_data if __name__ == '__main__': dat = get_yaml('D:\\python-pro\\login_pytest\\configs\\request.yaml') print(dat['logindata']['name'])
3 根据yaml文件记录的账号密码 来发送登录请求
from tool.get_md5 import get_md5 from tool.get_yaml import get_yaml import requests def login(data): # 老三样 第一 拼url # http://ip/account/sLogin?username=ct0356&password=96e79218965eb72c92a549dd5a330112 url='http://ip/account/sLogin' # 老三样 第二 请求体 payload = data # 老三样 第三 发送请求 res=requests.post(url,data) print(res.text) if __name__ == '__main__': yaml_url='D:\\python-pro\\login_pytest\\configs\\request.yaml' name=get_yaml(yaml_url)['logindata']['name'] psw = get_yaml(yaml_url)['logindata']['psw'] test_data = { 'username': name , 'password': get_md5(psw), } login(test_data)
标签:__,name,get,url,发送,yaml,post,data From: https://www.cnblogs.com/haha1988/p/17818501.html