记录一下request的简单用法
import requests
import json
"""首先保证单个接口的通过性
"""
def api_dl():
api_url = 'http://demo.phalapi.net/?s=App.Site.Index'
api_body = {'username': 'PhalApi'}
data_header= {}
res = requests.post(api_url, json=api_body)
res1=requests.post(url=api_url ,data=api_body ,headers=data_header)
#print(type(res.text))
# 将字符串转换成字典 转换时有中文不行时 utf-8一下 .encoding('utf8')
res.dict = json.loads(res.text)
#断言
if res.str['ret']==200:
print('接口调用成功')
else:
print('请检查入参是否正确')
#print(type(res.dict))
#print(res.dict['data'])
# api_dl()