[Python] Odoo API returns 'Invalid credentials' even with correct username and password

Discussão em 'Python' iniciado por Stack, Novembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I’m working with Odoo (version 15) and trying to implement a login API. I have created a controller that checks the username and password, but it always returns "Invalid credentials" even when I use the correct login information.

    Here’s my code:

    # -*- coding: utf-8 -*-
    from odoo import http

    class TestApi(http.Controller):
    @http.route("/api/check_login", methods=["POST"], type="json", auth="public", csrf=False)
    def check_login(self, **kwargs):
    username = kwargs.get('username')
    password = kwargs.get('password')

    if username == "admin" and password == "admin": # Replace with actual validation
    return {
    "message": "User is logged in.",
    "username": username
    }
    else:
    return {
    "error": "Invalid credentials."
    }


    Steps Taken: .I tested the API using Postman with a POST request to http:///api/check_login. .I used the following JSON body:

    {
    "username": "admin",
    "password": "admin"
    }


    .I confirmed that the credentials work in the Odoo web interface. Questions: What might be causing the API to not recognize valid credentials? Are there any additional configurations I should check? Is there a better method to handle user authentication in Odoo?

    Continue reading...

Compartilhe esta Página