requests库auth进行身份验证

import requests
from requests.auth import HTTPBasicAuth # 这个是必须要有的
import pytest
import yaml
# 打开我的Headers.yaml文件 with open(
'E:/wj/saas/UwbNetworkServer/common/YamlFile/MyHeaders.yaml','r',encoding='utf-8') as f: Headers = yaml.safe_load(f) with open('E:/wj/saas/UwbNetworkServer/common/YamlFile/uwb_network_api.yaml','r',encoding='utf-8') as f: my_host = yaml.safe_load(f) host = my_host['host1'] # 新建组织 def test_organization(): api = '/v1/organization' # 添加的url url = host + api my_body = { "maxApplicationCount": 10, "maxGatewayCount": 10, "maxRegionCount": 10, "maxTerminalCount": 10, "name": "我的组织" } rp = requests.request(method='post', url=url, auth=HTTPBasicAuth('xxxx@qq.com','12345678'), json=my_body) #
print(rp.text) assert rp.status_code == 200 assert "success" in rp.text
tips:HTTPBasicAuth是一个基础验证,参数是username,password,仅限于内部信任的网络使用,外部尽量不要用~
posted @ 2021-03-09 11:19  清风吹拂啊狂风肆虐  阅读(590)  评论(0编辑  收藏  举报