为Rest Api调用问题构造参数

时间:2019-02-23 02:40:20

标签: rest restful-url

我有示例Python代码,并且正在尝试构造和填充Rest API请求参数。

标头和授权参数工作正常,但是我不确定如何使用rest客户端为我的Rest请求转换下面提到的“ QueryBands”和“ data”变量。

queryBands = {} 
queryBands['appName'] = 'MyApp' 
queryBands['version'] = '1.0' 

# Setting request fields, including SQL. 

    data = {} 
    data['query'] = 'SELECT * from db limit 5' 
    data['queryBands'] = queryBands 
    data['format'] = 'array' 
    request = urllib2.Request(url, json.dumps(data), headers) 
    try: 
      response = urllib2.urlopen(request); 

我是否需要在进行Rest api调用时声明新变量或将这些值作为“ body”传递?

我正在使用chrome advance rest-client。但这可以是任何其他客户。

1 个答案:

答案 0 :(得分:0)

import json 
queryBands = {} 
queryBands['applicationName'] = 'MyApp'
queryBands['version'] = '1.0' 


data = {} 
data['query'] = 'SELECT * from db limit 5' 
data['queryBands'] = queryBands 
data['format'] = 'array' 

print(json.dumps(data))