Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
929 Vizualizări

Hello,


I’m having an issue with REST API authentication in Odoo 18, let me explain:


I’m developing an application with two components — a backend (Odoo) and a frontend (ReactJS).


On the Odoo side, I’ve created an authentication method where I call:


uid = request.session.authenticate(db_name, login, password)


But I’m getting the following error:


ERROR pioloop odoo.addons.property_rental.controllers.api.auth: Authentication error: Session.authenticate() takes 3 positional arguments but 4 were given



However, I don’t see where 4 parameters are being passed.


Has anyone encountered this kind of issue before?


For your information, I’m a beginner in Odoo.


Thanks in advance for your help.



Imagine profil
Abandonează
Autor Cel mai bun răspuns

Thanks a lot, it works great and unblocked me !

Imagine profil
Abandonează
Cel mai bun răspuns

See for example https://github.com/odoo/odoo/blob/18.0/addons/auth_signup/controllers/main.py#L173

    def _signup_with_values(self, token, values):
        login, password = request.env['res.users'].sudo().signup(values, token)
        request.env.cr.commit()     # as authenticate will use its own cursor we need to commit the current transaction
        credential = {'login': login, 'password': password, 'type': 'password'}
        request.session.authenticate(request.db, credential)

In other words, login and password aren't individual arguments but have to be combined into a dictionary.

You seem to be mixing it with the authenticate() method of the /web/session/authenticate route - this one indeed would be expecting db, login, password as individual arguments.


About 'takes x positional arguments but y were given':

Simply put, 'y' would always be +1 since self is also there. A more common example would be the create method:
It's defined as create(self, vals_list), however, when using it, you would do so by calling model.create(vals_list), omitting self - since model is self already.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
aug. 25
252
0
aug. 25
330
1
aug. 25
720
1
aug. 25
550
4
iul. 25
1949