0

I am new to odoo and I have created a module with the scaffold command as follows:

"C:\Program Files (x86)\Odoo 11.0\python\python.exe" "C:\Program Files (x86)\Odoo 11.0\server\odoo-bin" scaffold api4"C:\Users\Carlos\Desktop\custom_addons"

and when i create this base redirect controller it works fine

# - * - 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 /')

but when I create another @ http.route to receive a json and be able to process your data it doesn't work for me and the one I have done previously stops working.

    @ http.route ('/ api / json_get_request', auth = 'public', type = 'json', csrf = False)
    def jsontest (self, ** kw):
        return {'attribute': 'test'}

the code is basic but I wanted to see if sending any json would return {'attribute': 'test'} and instead it returned this:

{
    "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

  • I don't know know if it's the problem but when you send a json request odoo force you to send your data in the key `data` – Charif DZ Mar 14 '20 at 09:05

2 Answers2

0

Add -d or --db-filter in your odoo-bin command to single out only one database. For e.g. python3 odoo-bin --addons-path addons,mymodules -d newdatabase. As far as I know, api with auth='public' raise this kind of error when there are multiple odoo databases.

Alternative solution is you can use endpoint with auth='user'. You will need to get login cookie first tho. More on this: How to connect to Odoo database from an android application

Pyae
  • 500
  • 1
  • 4
  • 15
0

Hello 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

or

1) Use **--db-filter dabase-name** to load a single database.

And make sure your route defines there has no whitespace opt-in('/api/json_get_request').

Thanks

Dipen Shah
  • 2,396
  • 2
  • 9
  • 21