我是靠谱客的博主 威武裙子,这篇文章主要介绍用requests实现一个GET请求,并输出json格式文本,现在分享给大家,希望可以做个参考。

需要用到的两个点:

1.用josn格式打印

print(r.json())

2.get请求的方法

r = requests.request(”OPTIONS’, url, **kwargs)

api接口测试示例:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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()

多个值查询示例:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
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”)

最后

以上就是威武裙子最近收集整理的关于用requests实现一个GET请求,并输出json格式文本的全部内容,更多相关用requests实现一个GET请求内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部