Search code examples
pythonapiodoo

Issues with Odoo v13 UID/API


Having an issue with the api for Odoo v13. I am able to get the server info but for some reason the uid is not being returned

 import xmlrpc.client

url ="localhost:8069"
db = "pnv3"
username = "test"
password = "test"

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
print(common.version())

uid = common.authenticate(db, username, password, url)
print(uid)

getting this error

    Traceback (most recent call last):
  File "C:/Users/Web Content/.PyCharmCE2019.3/config/scratches/scratch.py", line 11, in <module>
    uid = common.authenticate(db, username, password, url)
  File "C:\Users\Web Content\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "C:\Users\Web Content\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1452, in __request
    verbose=self.__verbose
  File "C:\Users\Web Content\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Users\Web Content\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1170, in single_request
    return self.parse_response(resp)
  File "C:\Users\Web Content\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1342, in parse_response
    return u.close()
  File "C:\Users\Web Content\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: 'Traceback (most recent call last):\n  File "/odoo/odoo-server/odoo/modules/registry.py", line 59, in __new__\n    return cls.registries[db_name]\n  File "/odoo/odoo-server/odoo/tools/func.py", line 69, in wrapper\n    return func(self, *args, **kwargs)\n  File "/odoo/odoo-server/odoo/tools/lru.py", line 44, in __getitem__\n    a = self.d[obj].me\nKeyError: \'pnv3\'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "/odoo/odoo-server/odoo/addons/base/controllers/rpc.py", line 63, in xmlrpc_2\n    response = self._xmlrpc(service)\n  File "/odoo/odoo-server/odoo/addons/base/controllers/rpc.py", line 43, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n  File "/odoo/odoo-server/odoo/http.py", line 138, in dispatch_rpc\n    result = dispatch(method, params)\n  File "/odoo/odoo-server/odoo/service/common.py", line 61, in dispatch\n    return g[exp_method_name](*params)\n  File "/odoo/odoo-server/odoo/service/common.py", line 30, in exp_authenticate\n    res_users = odoo.registry(db)[\'res.users\']\n  File "/odoo/odoo-server/odoo/__init__.py", line 104, in registry\n    return modules.registry.Registry(database_name)\n  File "/odoo/odoo-server/odoo/modules/registry.py", line 61, in __new__\n    return cls.new(db_name)\n  File "/odoo/odoo-server/odoo/modules/registry.py", line 73, in new\n    registry.init(db_name)\n  File "/odoo/odoo-server/odoo/modules/registry.py", line 141, in init\n    with closing(self.cursor()) as cr:\n  File "/odoo/odoo-server/odoo/modules/registry.py", line 492, in cursor\n    return self._db.cursor()\n  File "/odoo/odoo-server/odoo/sql_db.py", line 649, in cursor\n    return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)\n  File "/odoo/odoo-server/odoo/sql_db.py", line 186, in __init__\n    self._cnx = pool.borrow(dsn)\n  File "/odoo/odoo-server/odoo/sql_db.py", line 532, in _locked\n    return fun(self, *args, **kwargs)\n  File "/odoo/odoo-server/odoo/sql_db.py", line 600, in borrow\n    **connection_info)\n  File "/usr/local/lib/python3.7/dist-packages/psycopg2/__init__.py", line 130, in connect\n    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)\npsycopg2.OperationalError: FATAL:  database "pnv3" does not exist\n\n'>

Process finished with exit cod

1

Databse does exist, have triple checked my password, not sure what else to do at this point.


Solution

  • The url to Odoo server should include protocol part "http://" in the beginning. Strange that you get the version info at all. What do you get as output for the version?

    Also you pass the url as the last parameter to authenticate method and this is not required. This should still not give the error you received.

    Try your code with these two fixes and report if this helps:

    import xmlrpc.client
    
    url ="http://localhost:8069"
    db = "pnv3"
    username = "test"
    password = "test"
    
    common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
    print(common.version())
    
    uid = common.authenticate(db, username, password, {})
    print(uid)
    

    Identical code works on my machine...