当前,我正在使用外部API,但oodoo网站“ https://www.odoo.com/documentation/11.0/webservices/odoo.html”中的代码不适用于我。

from xmlrpc import client

username = "admin"

pwd = "admin"

dbname = "testim17-11-19"

comp =0

sock_common = client.ServerProxy("http://localhost:8075/xmlrpc/common")

uid = sock_common.login(dbname, username, pwd)

sock = client.ServerProxy("http://localhost:8075/xmlrpc/object")

sock.execute_kw(dbname, uid, pwd,
'res.partner', 'search_read',
[[['is_company', '=', True], ['customer', '=', True]]],
{'fields': ['name', 'country_id', 'comment'], 'limit': 5})


但是我得到这个错误:

Traceback (most recent call last):
  File "get_csv2.py", line 20, in <module>
    {'fields': ['name', 'country_id', 'comment'], 'limit': 5})
  File "C:\Program Files (x86)\Python37-32\lib\xmlrpc\client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "C:\Program Files (x86)\Python37-32\lib\xmlrpc\client.py", line 1452, in __request
    verbose=self.__verbose
  File "C:\Program Files (x86)\Python37-32\lib\xmlrpc\client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Program Files (x86)\Python37-32\lib\xmlrpc\client.py", line 1170, in single_request
    return self.parse_response(resp)
  File "C:\Program Files (x86)\Python37-32\lib\xmlrpc\client.py", line 1342, in parse_response
    return u.close()
  File "C:\Program Files (x86)\Python37-32\lib\xmlrpc\client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault ERREUR:  l'opérateur n'existe pas : integer = boolean
LINE 1: SELECT COALESCE(password, '') FROM res_users WHERE id=false
                                                             ^
HINT:  Aucun opérateur ne correspond au nom donné et aux types d'arguments.
Vous devez ajouter des conversions explicites de type.
: 'Traceback (most recent call last):\n  File "c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\base\\controllers\\rpc.py", line 54, in xmlrpc_1\n    response = self._xmlrpc(service)\n  File "c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\base\\controllers\\rpc.py", line 43, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n  File "C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py", line 120, in dispatch_rpc\n    result = dispatch(method, params)\n  File "C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\service\\model.py", line 35, in dispatch\n    security.check(db,uid,passwd)\n  File "C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\service\\security.py", line 16, in check\n    return res_users.check(db, uid, passwd)\n  File "c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\base\\models\\res_users.py", line 612, in check\n    self._check_credentials(passwd)\n  File "c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\base\\models\\res_users.py", line 309, in _check_credentials\n    [self.env.user.id]\n  File "C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\sql_db.py", line 148, in wrapper\n    return f(self, *args, **kwargs)\n  File "C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\sql_db.py", line 225, in execute\n    res = self._obj.execute(query, params)\npsycopg2.ProgrammingError: ERREUR:  l\'opérateur n\'existe pas : integer = boolean\nLINE 1: SELECT COALESCE(password, \'\') FROM res_users WHERE id=false\n                                                             ^\nHINT:  Aucun opérateur ne correspond au nom donné et aux types d\'arguments.\nVous devez ajouter des conversions explicites de type.\n\n'>

最佳答案

错误是我输入了错误的用户名,所以uid为False。我修复了它,并且效果很好。

uid = sock_common.login(dbname, username, pwd)
print(uid)

关于python - Odoo外部API搜索和读取不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59052569/

10-14 12:14