1

如何用于测试需要身份验证postman的 odoo控制器方法?14.0

我曾经有一个简单的身份验证请求:

网址:http://localhost:8014/web/session/authenticate

方法:GET

标题:Content-Type: application/json

身体:

{
    "jsonrpc": "2.0", 
    "params": {
        "db": "v14pos", 
        "login": "admin", 
        "password": "admin"
    }
}

发送身份验证请求后,postman将设置session_idcookie,它将起作用。

但是,14.0即使session_id设置了 cookie,在尝试调用需要身份验证的 url 时,我也会收到以下错误:

{
    "jsonrpc": "2.0",
    "id": null,
    "error": {
        "code": 200,
        "message": "Odoo Server Error",
        "data": {
            "name": "odoo.exceptions.AccessDenied",
            "debug": "Traceback (most recent call last):\n  File \"/home/obi/src/vs/odoo14/addons/http_routing/models/ir_http.py\", line 450, in _dispatch\n    cls._authenticate(func)\n  File \"/home/obi/src/vs/odoo14/odoo/addons/base/models/ir_http.py\", line 132, in _authenticate\n    raise AccessDenied()\nException\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"/home/obi/src/vs/odoo14/odoo/http.py\", line 639, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"/home/obi/src/vs/odoo14/odoo/http.py\", line 315, in _handle_exception\n    raise exception.with_traceback(None) from new_cause\nodoo.exceptions.AccessDenied: Access Denied\n",
            "message": "Access Denied",
            "arguments": [
                "Access Denied"
            ],
            "context": {}
        }
    }
}

这对我有用 version 11.0

我注意到其中的 HTTP 标头以14.0不同的方式包含 cookie:

Cookie: TWISTED_SESSION=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2luZm8iOnsiYW5vbnltb3VzIjp0cnVlfSwiZXhwIjoxNjAzNjM0NDM5fQ.pJs2oOjQYOQrFnolafUlNZ4Bg4OMJ_itRaZPEUoaLeE; frontend_lang=en_US; fileToken=dummy-because-api-expects-one; tz=Africa/Khartoum; session_id=d36df662e749f368c32dcbecc07bf578dd57de8a

是什么TWISTED_SESSOIN?是不是造成了问题?

4

1 回答 1

1

我找到了解决方案,或者更确切地说是问题所在。

auth我在控制器方法中设置了错误的值,它是:

@http.route('/route/', auth='auth', type='json')

并将其更改为:

@http.route('/route/', auth='user', type='json')

于 2021-02-13T15:30:48.750 回答