Odoo 13 - json api 给出无效的 json 数据错误

问题描述

代码 -odoo 13 自定义模块

返回json数据的函数(rest api)

from odoo import http
from odoo.http import request,Response
import json


class OpenAcademy(http.Controller):
    @http.route('/opentest/',type='json',csrf=False,auth="none",methods=['GET'],)
    def update_order_webhook(self):

        return {
                'success': False,'error': 'no_tx_found',}

Error - <title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Invalid JSON data: ''</p>

当我明确定义 type="json" 时,也将内容类型返回为 text/html

解决方法

你返回字典...

尝试返回 json.dumps(your_dict)