Skip to Content
Menu
This question has been flagged
1 Reply
2481 Views

Hi, im trying to create a api rest. Reading online i found someone with the same problem. When i trying to do a get request, it return a 404 error in postman. Tried with the following command: --db-filter dabase-name and nothing worked.

 

controllers.py

@http.route('/tattoo/sessions', type='json', auth='public')
def get_sessions(self):
sessions_rec = request.env["tattoo.session"].search([])
sessions = []
for session in sessions_rec:
sessions.append({
"id": session.id,
"client_id": session.client_id
})
data = {"status": 200, "response": sessions, "message": "Success"}
return data

error:


{ "id": null, "error": { "data": { "arguments": [], "debug": "Traceback (most recent call last):\n File \"/home/johan/developement/odoo/odoo/http.py\", line 656, in _handle_exception\n return super(JsonRequest, self)._handle_exception(exception)\n File \"/home/johan/developement/odoo/odoo/http.py\", line 314, in _handle_exception\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n File \"/home/johan/developement/odoo/odoo/tools/pycompat.py\", line 86, in reraise\n raise value.with_traceback(tb)\nwerkzeug.exceptions.NotFound: 404: Not Found\n", "exception_type": "internal_error", "name": "werkzeug.exceptions.NotFound", "message": "404: Not Found" }, "code": 404, "message": "404: Not Found", "http_status": 404 }, "jsonrpc": "2.0"}

Avatar
Discard
Author

HI, thanks for answering. I have only one database and tried with .sudo() and it not worked


Author

resolved. problem: "from odoo.odoo import http" instead of "from odoo import http

Best Answer

If you have multi DB in your Odoo then you need to  db-filter. 

You can add sudo to search as below:

@http.route('/tattoo/sessions', type='json', auth='public')
def get_sessions(self):
sessions_rec = request.env["tattoo.session"].sudo().search([])
sessions = []
for session in sessions_rec:
sessions.append({
"id": session.id,
"client_id": session.client_id
})
data = {"status": 200, "response": sessions, "message": "Success"}
return data

Avatar
Discard