Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2607 มุมมอง

Hi everyone!
I developed the code below to read reports and data from odoo: 

import os

import xmlrpc.client

url = os.getenv('url')

db = os.getenv('db')

username = os.getenv('user')

password = os.getenv('password')

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

uid = common.authenticate(db, username, password,{})

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))models.execute_kw(db, uid, password,'sale.order','check_access_rights',['read'],{'raise_exception':False})

Unfortunately, this code got this error 


Fault: Fault 1: 'Traceback (most recent call last):\n  File "/opt/odoo14/odoo/odoo/addons/base/controllers/rpc.py", line 88, in xmlrpc_2\n    response = self._xmlrpc(service)\n  File "/opt/odoo14/odoo/odoo/addons/base/controllers/rpc.py", line 68, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n  File "/opt/odoo14/odoo/odoo/http.py", line 142, in dispatch_rpc\n    result = dispatch(method, params)\n  File "/opt/odoo14/odoo/odoo/service/model.py", line 37, in dispatch\n    security.check(db,uid,passwd)\n  File "/opt/odoo14/odoo/odoo/service/security.py", line 9, in check\n    return res_users.check(db, uid, passwd)\nTypeError: \'Boolean\' object is not callable




I do a research, finding out that my UID may be a error code, however I tried with other password and I got different error. In other words, my credential are correct, but I can't use the API with my user. 

I would be grateful with any handy hand. 

Best, 
Juan Grimaldos

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

try this way:
import os

import xmlrpc.client


url = os.getenv('url')

db = os.getenv('db')

username = os.getenv('user')

password = os.getenv('password')


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

uid = common.authenticate(db, username, password, {})


models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))


# Search for sale orders

sale_orders = models.execute_kw(db, uid, password, 'sale.order', 'search', [[]])


# Read data for the first sale order

if sale_orders:

order_data = models.execute_kw(db, uid, password, 'sale.order', 'read', [sale_orders[0]])

print(order_data)

else:

print("No sale orders found.")


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,
1- Make certain that the Odoo API version being employed is the appropriate one, specifically XML-RPC version 2, which corresponds to Odoo 14.
2- Please verify that the URL is accurately directed to the correct Odoo server and that the database name is correct.
3- Ensure that the 'username' and 'password' variables contain the accurate login credentials for the specific Odoo user intended to access the API.
4- Ensure that the 'common.authenticate' function is functioning correctly and providing a valid 'uid,' which is essential for making subsequent API calls.
5- Verify whether all the essential Python dependencies and libraries required for making XML-RPC requests have been installed.
6- Check API Call: Review the 'models.execute_kw' call and ensure that all the parameters are correct. The format should be 'models.execute_kw(db, uid, password, model, method, args, kwargs)'.
7- Exception Handling, you can add exception handling to your code to catch any errors that may occur during the API calls.

eg:-

try:
    uid = common.authenticate(db, username, password, {})
except Exception as e:
    print("Authentication Error occurred:", e)


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ต.ค. 24
31183
1
ก.ค. 23
6117
0
พ.ค. 23
1786
1
มี.ค. 24
4211
1
ม.ค. 23
1191