我正在尝试使用 Flask 和请求构建一个简单的代理。代码如下:
@app.route('/es/<string:index>/<string:type>/<string:id>',
methods=['GET', 'POST', 'PUT']):
def es(index, type, id):
elasticsearch = find_out_where_elasticsearch_lives()
# also handle some authentication
url = '%s%s%s%s' % (elasticsearch, index, type, id)
esreq = requests.Request(method=request.method, url=url,
headers=request.headers, data=request.data)
resp = requests.Session().send(esreq.prepare())
return resp.text
这可行,只是它会丢失 Elasticsearch 的状态代码。我尝试直接返回resp
(a requests.models.Response
),但这失败了
TypeError: 'Response' object is not callable
是否有另一种简单的方法requests.models.Response
从 Flask 返回一个?