跳至內容
選單
此問題已被標幟
2 回覆
160 瀏覽次數

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.



頭像
捨棄
作者 最佳答案

Thanks a lot, it works great and unblocked me !

頭像
捨棄
最佳答案

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.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
7月 25
109
1
7月 25
181
1
7月 25
258
1
7月 25
423
0
7月 25
382