如何在请求后捕获bottlepy响应中的JSON?

2024-03-29 15:47:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我要用Bootle Py记录所有web服务响应。 最好的方法是什么?你知道吗

我正在用以下代码写入MongoDB数据库:

@hook('after_request')
def f_after_request():
    if request['bottle.route'].rule not in [
        '/robots.txt',
        '/favicon.ico',
    ]:
        json_in = None
        if request.method not in ['GET']:
            json_in = request.json
        _save_in_out_message(
            url=bottle.request.url,
            json_in=json_in,
            json_out=bottle.response.get_data(),
            status_code=response.status_code,
            method=request.method
        )

但是response.get_data()不存在。你知道吗

如何在请求后捕获bottlepy响应中的JSON?你知道吗

正确的response.get_data()命令是什么?你知道吗

谢谢


Tags: injsonurlbottledatagetifresponse