【发布时间】:2016-03-10 10:30:58
【问题描述】:
我正在尝试向 Odoo 控制器发送一些 JSON 数据,但是当我发送请求时,我总是得到 404 作为响应。
这是我的控制器的代码:
import openerp.http as http
import logging
_logger = logging.getLogger(__name__)
class Controller(http.Controller):
@http.route('/test/result', type='json', auth='public')
def index(self, **args):
_logger.info('The controller is called.')
return '{"response": "OK"}'
现在,我在浏览器上键入 URL (http://localhost:8069/test/result) 以检查它是否可用,我得到 function index at 0x7f04a28>, /test/result: Function declared as capable of handling request of type 'json' but called with a request of type 'http'。这样我就知道控制器正在侦听该 URL 并期待 JSON 数据。
所以我打开一个 Python 控制台并输入:
import json
import requests
data = {'test': 'Hello'}
data_json = json.dumps(data)
r = requests.get('http://localhost:8069/test/result', data=data_json)
当我在控制台中打印 r 时,它返回
这里有一个类似的问题,但不是完全一样的情况:
OpenERP @http.route('demo_json', type="json") URL not displaying JSON Data
谁能帮帮我?我做错了什么?
【问题讨论】:
标签: json python-2.7 controller odoo-8 odoo