Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
1382 Vistas

i try to use xml rpc to read the calendar.event model :


 


model_name = 'calendar.event'
search_domain = []
search_result = models.execute_kw(db, uid, password, model_name, 'search_read', [search_domain]) 
print(search_result) 



but i get this error :

Traceback (most recent call last):
  File "c:\Users\PC\Desktop\New folder\models.py", line 5846, in ensure_one\n    raise ValueError("Expected singleton: %s" % self)\nValueError: Expected singleton: calendar.event(6, 3, 5, 4, 2, 1)\n'> 



can someone please explain for me what is the problem and how to use it correctely 

Avatar
Descartar
Mejor respuesta

Hi,
At first look the code, seems to be fine, does it raise error if you remove the print(search_result) line ?

Also just change the model name to a different model like res.partner and see if that works and something wrong with this model only, so that it can be checked

Odoo XMLRPC: Search Read Method To Read From Database


Also specify the field names and see, it that brings any difference:

models.execute_kw(db, uid, password, model_name, 'search_read', [[]], {'fields': ['name']})


Thanks

Avatar
Descartar
Mejor respuesta

Hi,

The error is arising due to there is more that one record contain in the search_result while you printing it. So to avoid singleton error provide a lupin in you function

Example:

search_result = models.execute_kw(db, uid, password, model_name, 'search_read', [search_domain])

for record in  search_result:  

    print(record)


Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
5
feb 24
8483
0
nov 16
2888
1
jun 25
473
2
jun 25
2074
2
nov 24
8659