
普通接口测试代码 -data表单数据✔传表单格式✔不会自动加Content-Type: application/json✔字典会被转成keyvaluekeyvalueimport requests # 1. 登录 resp requests.request( methodpost, urlhttp://api.fbi.com:9225/rest-v2/login/access_token, data{ email: bfqq.com, password: bf123456 } ) print(resp.status_code) # 人工判断 if resp.status_code 200: # 自动判断 print(成功) else: print(失败)普通接口测试代码 -json字符串数据✔传 JSON 格式✔自动加请求头Content-Type: application/json✔字典会被转成 JSON 字符串import requests # 1. 登录 resp requests.request( methodpost, urlhttp://api.fbi.com:9225/rest-v2/login/access_token, json{ email: bfqq.com, password: bf123456 } ) print(resp.status_code) # 人工判断 if resp.status_code 200: # 自动判断 print(成功) else: print(失败)文件上传接口测试代码import requests # 1. 登录 resp requests.request( methodpost, urlhttp://api.fbi.com:9225/rest-v2/login/access_token, files{ email: open(北凡老师pytest高手课.mp4, rb), password: open(北凡老师测试平台实战课.mp4, rb), } ) print(resp.status_code) # 人工判断 if resp.status_code 200: # 自动判断 print(成功) else: print(失败)总结ps 拿apiFox为例可查看对应的python代码