return返回axios的返回值

在用axios请求python服务的时候,碰到个问题,axios一直获取不到python的返回值,
后面看了下,解决办法如下:
这里是python服务端的返回代码,

	self.send_response(200)
    self.send_header('Content-Type', 'application/json')
    self.end_headers()
    self.wfile.write(json.dumps(resp).encode("utf-8"))

在axios里接收的话,

async function (step, callback, ctx) {
	ctx.set(step.parameters.rename, await python_exec(data));
}

其中python_exec是实际请求部分,

return axios({
        method: 'post',
        url:url,
        data: data,
        headers: headers
    })
        .then(function(response) {
            return response.data.content;
        })
        .catch(function (error) {
            console.log(error);
        });

使用async,await,return就可以获取到实际的返回值,

你可能感兴趣的:(axios,ajax,node.js,javascript)