Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 NotFound #32

Open
HamaniKhalil opened this issue Mar 22, 2020 · 3 comments
Open

404 NotFound #32

HamaniKhalil opened this issue Mar 22, 2020 · 3 comments

Comments

@HamaniKhalil
Copy link

I've tried to GET from res.users using postman, and here's my request :

GET /api/res.users
Request Body

{
    "params": {
        "session_id": "19c6f61a6680310ad9aef098a1fdbc45c5d6f388"
    }
}

(I tried using only the Cookie header but it didn't work so I sent the session_id as a parameter as mentioned in the documentation)

Response

{
    "jsonrpc": "2.0",
    "id": null,
    "error": {
        "message": "404: Not Found",
        "code": 404,
        "data": {
            "debug": "Traceback (most recent call last):\n  File \"/usr/lib/python2.7/dist-packages/odoo/http.py\", line 642, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_http.py\", line 177, in _dispatch\n    rule, arguments = cls._find_handler(return_rule=True)\n  File \"/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_http.py\", line 79, in _find_handler\n    return cls.routing_map().bind_to_environ(request.httprequest.environ).match(return_rule=return_rule)\n  File \"/usr/lib/python2.7/dist-packages/werkzeug/routing.py\", line 1430, in match\n    raise NotFound()\nNotFound: 404: Not Found\n",
            "exception_type": "internal_error",
            "message": "404: Not Found",
            "name": "werkzeug.exceptions.NotFound",
            "arguments": []
        },
        "http_status": 404
    }
}
@altanmur
Copy link

Hello

  • Body - None (because first call /web/session/authenticate then after session_id included on all requests header)
  • Header - No content-type
  • Method - Get
  • Params - key => query, value=>{id,name}

First Request - Web/session/authenticate
Screen Shot 2020-04-22 at 07 34 18

Second Request - GET /api/res.users
Screen Shot 2020-04-22 at 07 34 26

@yezyilomo
Copy link
Owner

If you want to use /auth/ route for authentication this examples might help

import json
import requests

AUTH_URL = 'http://localhost:8069/auth/'

headers = {'Content-type': 'application/json'}


# Remember to configure default db on odoo configuration file(dbfilter = ^db_name$)
# Authentication credentials
data = {
    'params': {
         'login': '[email protected]',
         'password': 'yor_password',
         'db': 'your_db_name'
    }
}

# Authenticate user
res = requests.post(
    AUTH_URL, 
    data=json.dumps(data), 
    headers=headers
)

# Get session_id from the response
# We are going to use this as our API key
session_id = json.loads(res.text)['result']['session_id']


# Example 1
# Get users
USERS_URL = 'http://localhost:8069/api/res.users/'

# Pass session_id for auth
# This will take time since it retrives all res.users fields
# You can use query param to fetch specific fields
params = {'session_id': session_id}

res = requests.get(
    USERS_URL, 
    params=params
)

# This will be a very long response since it has many data
print(res.text)


# Example 2
# Get products(assuming you have products in you db)
# Here am using query param to fetch only product id and name(This will be faster)
USERS_URL = 'http://localhost:8069/api/product.product/'

# Pass session_id for auth
params = {'session_id': session_id, 'query': '{id, name}'}

res = requests.get(
    USERS_URL, 
    params=params
)

# This will be small since we've retrieved only id and name
print(res.text)

@m-abdalrahman
Copy link

@yezyilomo this example not working with odoo version 10
I get this error:

Traceback (most recent call last):
File "auth.py", line 28, in
session_id = json.loads(res.text)['result']['session_id']
KeyError: 'result'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants