Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Session Expired For /web/session/authenticate access through python

Subscribe

Get notified when there's activity on this post

This question has been flagged
sessioncontrollerspython3odoo12
2 Replies
27795 Views
Avatar
SSS

Hello,

I am trying to access /web/session/authenticate using python as:

>>> import requests
>>> import json
>>> url = "http://localhost:8089/web/session/authenticate"
>>> headers = {'Content-Type':'application/json'}
>>> data = json.dumps({"params":{"db":"test","login":"admin","password":"admin"}})
>>> r = requests.post(url=url,data=data,headers=headers)

but it gives me following error:

@page { margin: 2cm } p { margin-bottom: 0.25cm; line-height: 115% }

b'{"jsonrpc": "2.0", "id": null, "error": {"code": 404, "message": "404: Not Found", "data": {"name": "werkzeug.exceptions.NotFound", "debug": "Traceback (most recent call last):\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/http.py\\", line 656, in _handle_exception\\n return super(JsonRequest, self)._handle_exception(exception)\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/http.py\\", line 314, in _handle_exception\\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/tools/pycompat.py\\", line 87, in reraise\\n raise value\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/http.py\\", line 1460, in _dispatch_nodb\\n func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()\\n File \\"/usr/local/lib/python3.6/dist-packages/werkzeug/routing.py\\", line 1563, in match\\n raise NotFound()\\nwerkzeug.exceptions.NotFound: 404: Not Found\\n", "message": "404: Not Found", "arguments": [], "exception_type": "internal_error"}, "http_status": 404}}

After changing config file as dbfilter = test gives me following error:

b'{"jsonrpc": "2.0", "id": null, "error": {"code": 100, "message": "Odoo Session Expired", "data": {"name": "odoo.http.SessionExpiredException", "debug": "Traceback (most recent call last):\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/http.py\\", line 656, in _handle_exception\\n return super(JsonRequest, self)._handle_exception(exception)\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/http.py\\", line 314, in _handle_exception\\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/tools/pycompat.py\\", line 87, in reraise\\n raise value\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/addons/http_routing/models/ir_http.py\\", line 346, in _dispatch\\n cls._authenticate(func.routing[\'auth\'])\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/addons/base/models/ir_http.py\\", line 118, in _authenticate\\n getattr(cls, \\"_auth_method_%s\\" % auth_method)()\\n File \\"/usr/local/sampada/eclipse-workspace/odoo12/odoo/addons/base/models/ir_http.py\\", line 91, in _auth_method_user\\n raise http.SessionExpiredException(\\"Session expired\\")\\nodoo.http.SessionExpiredException: Session expired\\n", "message": "Session expired", "arguments": ["Session expired"], "exception_type": "internal_error"}}}

after clearing history, cookies and destroying sessions of user still same error occur


 
0
Avatar
Discard
Avatar
Maduka Sopulu
Best Answer

You need to get the session id and pass it as cookie

here is the code example

parameter = {

            "db": "dbname",

            "login": "admin@gmail.com",

            "password": "admin",    

                        }

 

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

AUTH_URL = "http://127.0.0.1:8072/web/session/authenticate/"

data = {

        "jsonrpc": "2.0",

        "params": {

                "login": parameter['login'],

                "password": parameter['password'],

                "db": parameter['db']

            }

        }  

res = rq.post(AUTH_URL, data=json.dumps(data),headers=headers)

session_id = res.cookies["session_id"]

base_url = "127.0.0.1:8072/api/v1/modules/" # your api 

json_data = json.dumps(parameter)

json_headers = {

    "Content-Type": "application/json",

    "Accept": "application/json",

    }

'''cookies = {

    'login': "admin@gmail.com", 

    'password': 'admin',

    'session_id':session_id

    }'''

req = rq.post("http://{}".format(base_url), data = json_data, headers=json_headers, cookies=cookies)

print(req.content) 

1
Avatar
Discard
Avatar
Ravi Gadhia
Best Answer

Hi 
It seems everything is ok and it should work. 
but as error point out "Session expired" it should only occur in case of auth='user' on the route. 
however 'web/session/authenticate' route is auth="none" type so are you sure it's not overridden by another module (it change auth none to user)?

0
Avatar
Discard
SSS
Author

Yes I have change auth=none to auth=user. For auth=none work fine but I want authenticate user that is reason I am changing auth=user.how to authenticate user if auth=user?

Ravi Gadhia

auth="user" mean Http layer first check the user is logged in (it has a valid session-id) while auth="none" means it doesn't' check user authentication.

use of route /web/session/authenticate who have user credential can request this route and get a session which used for further communion. so this route must be auth="none" otherwise there is no need to authenticate if a user already login

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
I want to populate Customer/Vendor Many2one field based on Selection Field which has two selection 1.Sale Order, 2.Purchase Order. If it is Sale Order then Many2one field should have Customers from sale.order model and if it is Purchase Order then Many2one field should have Vendors from purchase.order model. v:odoo12 Solved
python3 odoo12
Avatar
Avatar
Avatar
3
Dec 22
4260
how to session expire in odoo?
session odoo12
Avatar
0
Nov 22
1908
No data in POST Solved
controllers odoo12
Avatar
1
Oct 20
3532
How to make sign up menu in website? Solved
python3 odoo12
Avatar
Avatar
2
Apr 20
5373
Multi Assign to one task?
python3 odoo12
Avatar
Avatar
1
Apr 20
4333
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now