I am using odoo V16. When I send a POST request to web/session/authenticate endpoint with the correct user credentials in the body like this:
{
"params": {
"db":<DB>,
"login": <LOGIN>,
"password": <PASSWORD>
}
}
I get a bad response with the error message "'NoneType' object has no attribute 'user'". The expected behavior is a JSON response with session info like:
{
"jsonrpc": "2.0",
"id": null,
"result": {...}
}
I'm not sure if it is a bug in the new odoo version or I'm doing something wrong. Any help is appreciated. Thanks!
Full error response:
{ "jsonrpc": "2.0", "id": null, "error": { "code": 200, "message": "Odoo Server Error", "data": { "name": "builtins.AttributeError", "debug": "Traceback (most recent call last): File "/odoo-16/odoo/http.py", line 1963, in call response = request._serve_nodb() File "/odoo-16/odoo/http.py", line 1516, in _serve_nodb response = self.dispatcher.dispatch(rule.endpoint, args) File "/odoo-16/odoo/http.py", line 1775, in dispatch result = endpoint(**self.request.params) File "/odoo-16/odoo/http.py", line 673, in route_wrapper result = endpoint(self, *args, **params_ok) File "/odoo-16/addons/web/controllers/session.py", line 52, in authenticate print('session_info', env['ir.http'].session_info()) File "/odoo-16/addons/web_tour/models/ir_http.py", line 12, in session_info result = super().session_info() File "/odoo-16/addons/web/models/ir_http.py", line 68, in session_info user = request.env.user AttributeError: 'NoneType' object has no attribute 'user' ", "message": "'NoneType' object has no attribute 'user'", "arguments": [ "'NoneType' object has no attribute 'user'" ], "context": {} } } }
I faced the same problem, and I found a workaround.
The problem happen when you call the Odoo API for authentication web/session/authenticate
.
We usually send the login data like this in POST
request to the server
{"params":{"db":"odoo16","login":"admin","password":"***"}}
I got the error saying:
File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/ir_http.py", line 17, in session_info
user = request.env.user
AttributeError: 'NoneType' object has no attribute 'user'
This problem Happen when you has many databases
in the server, so the request handler fail in fetching the user
from env
variable.
But if you update your odoo.conf
and added a dbfilter = odoo16
, and restart the server. you will have only one database like this:
Then if you call the API you will get the CORRECT response and works fine
with you,
{
"jsonrpc": "2.0",
"id": null,
"result": {
"uid": 2,
"is_system": true,
"is_admin": true,
"user_context": {
"lang": "en_US",
"tz": "Africa/Cairo",
"uid": 2
},
...
...
...
}
}
Hope this help you fixing your issue till Odoo fix there bug.