Odoo JSONRPC 服务 (http.route type=json) 不工作
Odoo JSONRPC service (http.route type=json) not work
我正在尝试在 odoo 中创建 jsonrpc 服务。当我使用 doc https://www.odoo.com/documentation/8.0/howtos/website.html 创建干净的模块并添加这样的代码时
**[controllers.py]**
@http.route(['/my_academy/ret/'], type='json', auth="public")
def change_size(self):
return {'x': 1, 'y': 2}
尝试从 js 连接:
"use strict";
var requestUrl = '/my_academy/ret/';
openerp.jsonRpc(requestUrl, 'call', {})
.then(function (data) {
alert(data['x']);
});
一切正常。我收到消息“1”。
当我使用 doc https://www.odoo.com/documentation/8.0/howtos/backend.html 创建模块并添加这样的代码时
**[controllers.py]**
@http.route(['/academy/jsonrpc/'], type='json', auth="public")
def return_map(self):
return {'x': 12345, 'y': 2222}
修改js并尝试连接
"use strict";
var requestUrl = '/academy/jsonrpc/';
openerp.jsonRpc(requestUrl, 'call', {})
.then(function (data) {
alert(data['x']);
});
我收到错误
code: 200
data: Object
arguments: Array[0]
length: 0
__proto__: Array[0]
....
debug: "Traceback (most recent call last):↵
File "/home/skif/odoo/openerp/http.py", line 539, in _handle_exception↵
return super(JsonRequest, self)._handle_exception(exception)↵
File "/home/skif/odoo/openerp/addons/base/ir/ir_http.py", line 152, in _dispatch↵
rule, arguments = self._find_handler(return_rule=True)↵
File "/home/skif/odoo/openerp/addons/base/ir/ir_http.py", line 65, in _find_handler↵
return self.routing_map().bind_to_environ(request.httprequest.environ).match(return_rule=return_rule)↵
File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1430, in match↵
raise NotFound()↵
NotFound: 404: Not Found↵"
message: ""
name: "werkzeug.exceptions.NotFound"
__proto__: Object
message: "Odoo Server Error"
__proto__:Object
我做错了什么?为什么我不能使用类似的代码?
试试这个代码:
@http.route(['/academy/jsonrpc'], type='json', auth="public", website=True)
def return_map(self, **post):
return {'x': 12345, 'y': 2222}
它可能对您的情况有所帮助。
我正在尝试在 odoo 中创建 jsonrpc 服务。当我使用 doc https://www.odoo.com/documentation/8.0/howtos/website.html 创建干净的模块并添加这样的代码时
**[controllers.py]**
@http.route(['/my_academy/ret/'], type='json', auth="public")
def change_size(self):
return {'x': 1, 'y': 2}
尝试从 js 连接:
"use strict";
var requestUrl = '/my_academy/ret/';
openerp.jsonRpc(requestUrl, 'call', {})
.then(function (data) {
alert(data['x']);
});
一切正常。我收到消息“1”。 当我使用 doc https://www.odoo.com/documentation/8.0/howtos/backend.html 创建模块并添加这样的代码时
**[controllers.py]**
@http.route(['/academy/jsonrpc/'], type='json', auth="public")
def return_map(self):
return {'x': 12345, 'y': 2222}
修改js并尝试连接
"use strict";
var requestUrl = '/academy/jsonrpc/';
openerp.jsonRpc(requestUrl, 'call', {})
.then(function (data) {
alert(data['x']);
});
我收到错误
code: 200
data: Object
arguments: Array[0]
length: 0
__proto__: Array[0]
....
debug: "Traceback (most recent call last):↵
File "/home/skif/odoo/openerp/http.py", line 539, in _handle_exception↵
return super(JsonRequest, self)._handle_exception(exception)↵
File "/home/skif/odoo/openerp/addons/base/ir/ir_http.py", line 152, in _dispatch↵
rule, arguments = self._find_handler(return_rule=True)↵
File "/home/skif/odoo/openerp/addons/base/ir/ir_http.py", line 65, in _find_handler↵
return self.routing_map().bind_to_environ(request.httprequest.environ).match(return_rule=return_rule)↵
File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1430, in match↵
raise NotFound()↵
NotFound: 404: Not Found↵"
message: ""
name: "werkzeug.exceptions.NotFound"
__proto__: Object
message: "Odoo Server Error"
__proto__:Object
我做错了什么?为什么我不能使用类似的代码?
试试这个代码:
@http.route(['/academy/jsonrpc'], type='json', auth="public", website=True)
def return_map(self, **post):
return {'x': 12345, 'y': 2222}
它可能对您的情况有所帮助。