admin管理员组

文章数量:1122846

I'm trying to send a GET request to my Odoo API endpoint using Postman, but I'm encountering a "403 Forbidden" error. Here are the details of my setup:

  • Odoo Version: [ Odoo 15 community]

  • API Endpoint: http://localhost:8069/api/postman

  • Authentication: I'm using Basic Authentication with the following credentials:

    • Username: [admin] it is my odoo username

    • Password: [ admin] it is my odoo password

This is the full error message I receive when I click send: xml

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>403 Forbidden</title>
<h1>Forbidden</h1>
<p>You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.</p>

Here’s the relevant part of my Odoo controller where I defined the route:

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

class TestApi(http.Controller):
    @http.route("/api/postman", methods=["GET"], type="http", auth="basic", csrf=False)
    def test_endpoint(self):
        return "This is a test API endpoint with basic authentication."

Steps I’ve Taken:
I have verified that my user credentials are correct.
The user has the necessary permissions to access the API.
The API endpoint is correctly configured to use Basic Authentication.

I'm trying to send a GET request to my Odoo API endpoint using Postman, but I'm encountering a "403 Forbidden" error. Here are the details of my setup:

  • Odoo Version: [ Odoo 15 community]

  • API Endpoint: http://localhost:8069/api/postman

  • Authentication: I'm using Basic Authentication with the following credentials:

    • Username: [admin] it is my odoo username

    • Password: [ admin] it is my odoo password

This is the full error message I receive when I click send: xml

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>403 Forbidden</title>
<h1>Forbidden</h1>
<p>You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.</p>

Here’s the relevant part of my Odoo controller where I defined the route:

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

class TestApi(http.Controller):
    @http.route("/api/postman", methods=["GET"], type="http", auth="basic", csrf=False)
    def test_endpoint(self):
        return "This is a test API endpoint with basic authentication."

Steps I’ve Taken:
I have verified that my user credentials are correct.
The user has the necessary permissions to access the API.
The API endpoint is correctly configured to use Basic Authentication.

Share Improve this question edited Nov 21, 2024 at 18:24 Brian Tompsett - 汤莱恩 5,87572 gold badges61 silver badges133 bronze badges asked Nov 21, 2024 at 17:47 sarmsarm 331 silver badge3 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Your problem is the auth="basic". This is not a recognised authentication method for Odoo. Odoo's @http.route only accepts 'user', 'public' or 'none'. You can check the usage documentation on odoo/odoo/http.py:route() method.

Erase in odoo doesn'T really support the authentication you want. This code just isn't there. The ode has its own authentication option. When you set "user" it turns on. It consists in the fact that you must first receive a cookie. And then in the postman already pass these cookies in the cookie header. I am sending examples of authentication and subsequent requests from my mobile app. I think it will be clear to you and you will transfer it to the postman. next how use this cookie So you can'T get the data in one request. First you need to get a cookie(token). And then make a request with this cookie. Also note that cookies also come in the set-cookie header By the way, there is another alternative option to create an API KEY in the user's settings and use it. If you want implement basic auth on your custom controller you should do like this. This is my implementation of the basic.

本文标签: