Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
248 Zobrazení

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.



Avatar
Zrušit
Autor Nejlepší odpověď

Thanks a lot, it works great and unblocked me !

Avatar
Zrušit
Nejlepší odpověď

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.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
čvc 25
232
2
čvc 25
954
4
čvc 25
800
1
čvc 25
111
1
čvc 25
293