postman 在odoo中创建一个控制器来处理json

1hdlvixo  于 12个月前  发布在  Postman
关注(0)|答案(2)|浏览(98)

我是odoo的新手,我用scaffold命令创建了一个模块,如下所示:
“C:\Program Files(x86)\Odoo 11.0\python\python.exe”“C:\Program Files(x86)\Odoo 11.0\server\odoo-bin”scaffold api 4“C:\Users\卡洛斯\桌面\自定义插件”
当我创建这个基本的重定向控制器时,它工作正常。

# - * - 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
    }
}


error postman

euoag5mw

euoag5mw1#

在odoo-bin命令中添加-d--db-filter,以便只选择一个数据库。例如python3 odoo-bin --addons-path addons,mymodules -d newdatabase。据我所知,auth='public'的API在有多个odoo数据库时会引发此类错误。
另一种解决方案是你可以使用auth='user'的端点。你需要先获得登录cookie。更多关于这个:How to connect to Odoo database from an android application

ndh0cuux

ndh0cuux2#

你好,卡洛斯,阿尔贝托·弗洛里奥·路易斯,

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'**)。
谢谢

相关问题