需要用到的两个点:
1.用josn格式打印
print(r.json())
2.get请求的方法
r = requests.request(”OPTIONS’, url, **kwargs)
api接口测试示例:
import requests
'''获取交易对数据'''
def ExchangeInfo():
url = "http://192.168.2.11/api/v1/exchangeInfo"
headers = {
'Cache-Control': "no-cache",
'test_1-Token': "33493898-b20e-479b-8ba7-426370ab3659"
}
response = requests.request("GET", url, headers=headers)
print(response.json()) #返回json格式文本 要返回text文本则用r.text
ExchangeInfo()
多个值查询示例:
a= ["ae_btc","tok_btc","eth_btc"] # 定义一个包含i个交易对列表,输入到查询字段的字典中
i=0
while i<3: #使用循环,将三个数值分别传入查询
Trades_info = {"size":"10","symbol":a} # 字典+列表的使用,方便后期更改输入值
headers = {
'Cache-Control': "no-cache",
'Postman-Token': "d45bd0ae-ca30-4df1-843b-73895545bfd5"
}
response = requests.request("GET",url,headers=headers,params=Trades_info)
i +=i
print(response.json())
其他request请求的用法https://blog.csdn.net/wgxshr/article/details/60782029(提示:文中关于requests.request的叙述,方法用的’get’单引号,应用双引号”get”)