我是odoo的新手,我用scaffold命令创建了一个模块,如下所示:
"C:\Program Files(x86(\Odoo 11.0\python\python.exe"C:\Program Files\Odoo 11.0\server\Odoo-bin"scaffold api4"C:\Users\Carlos\Desktop\custom_addons">
当我创建这个基本重定向控制器时,它工作得很好
# - * - coding: utf-8 - * -
from odoo import http
from odoo.http import request
import json
class Api4 (http.Controller):
@ http.route ('/ api4 / api4 /', auth = 'public', website = True)
def index (self):
return request.redirect ('/ web /')
但是,当我创建另一个@http.route来接收json并能够处理您的数据时,它对我来说不起作用,而且我以前做过的那个也停止了工作。
@ http.route ('/ api / json_get_request', auth = 'public', type = 'json', csrf = False)
def jsontest (self, ** kw):
return {'attribute': 'test'}
代码是基本的,但我想看看发送任何json是否会返回{‘attribute’:‘test’},而它返回的是:
{
"jsonrpc": "2.0",
"id": null,
"error": {
"code": 404,
"message": "404: Not Found",
"data": {
"name": "werkzeug.exceptions.NotFound",
"debug": "Traceback (most recent call last): n File " C: \ Program Files (x86) \ Odoo 11.0 \ server \ odoo \ http.py ", line 653, in _handle_exception n return super (JsonRequest, self) ._ handle_exception (exception) n File "C: \ Program Files (x86) \ Odoo 11.0 \ server \ odoo \ http.py ", line 312, in _handle_exception n raise pycompat.reraise (type (exception), exception, sys.exc_info () [2]) n File "C: \ Program Files (x86) \ Odoo 11.0 \ server \ odoo \ tools \ pycompat.py ", line 86, in reraise n raise value.with_traceback (tb) nwerkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. n ",
"message": "404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"arguments": [],
"exception_type": "internal_error"
},
"http_status": 404
}
}
错误邮递员
在odoo-bin命令中添加-d
或--db-filter
以仅挑出一个数据库。例如CCD_ 3。据我所知,当有多个odoo数据库时,带有auth='public'
的api会引发这种错误。
另一种解决方案是您可以将端点与auth='user'
一起使用。您需要首先获得登录cookie。更多关于这个:如何从android应用程序连接到Odoo数据库
你好Carlos Alberto Florio Luis,
1) Clear all the cache and history in your browser.
2) keep only one database for use and remove other databases
或
1) Use **--db-filter dabase-name** to load a single database.
并确保您的路由定义没有空白选择加入('/api/json_get_request'(。
感谢