使用axios从Flask-restless API获取数据

时间:2018-09-14 00:51:45

标签: python flask axios flask-restless

我正在尝试使用axios从不停瓶的API中获取数据。以下Python请求无法正常工作:

import requests
import json

url = 'http://127.0.0.1:5001/api/cds'
headers = {'Content-Type': 'application/json'}

filters = [dict(name='formal_name', op='like', val='my_val')]
params = dict(q=json.dumps(dict(filters=filters)))

response = requests.get(url, params=params, headers=headers)

并生成此URI

/api/cds?q=%7B%22filters%22%3A+%5B%7B%22name%22%3A+%22formal_name%22%2C+%22op%22%3A+%22like%22%2C+%22val%22%3A+%22my_val%22%7D%5D%7D

与axios类似的请求:

axios.get('http://127.0.0.1:5001/api/cds', {
      params: {
        q:
            JSON.stringify({
              filters: [{
                name: "formal_name",
                op: "like",
                val: formalName
              }]
            })
      },
    }
)
    .then(res => {
      console.log(res)
    });

请求其他URI:

/api/cds?q=%7B%22filters%22:[%7B%22name%22:%22formal_name%22,%22op%22:%22like%22,%22val%22:%22my_val%22%7D]%7D 

最终没有返回结果。我想知道我在axios中使用的语法方面是否缺少某些东西,或者axios生成不同的URI(然后无法通过flask-restless正确解析)是否有一些根本原因?

0 个答案:

没有答案