我正在尝试通过客户端 xmlprc 库创建日志注释,方法是通过帮助台模块中的 json 文件读取日志注释,但却遇到了名为“位置参数不符合预期”的 typeError。错误如下:-
TypeError:MailThread.message_post 需要 1 个位置参数,但是给出了 3 个。
下面是我的代码:
import json
import xmlrpc.client
db18 = 'test' # write your database
user18 = 'admin' # write your user
password18 = 'admin'
url18 = 'http://localhost:8018'
common18 = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url18))
uid18 = common18.authenticate(db18, user18, password18, {})
print("uid::::::::::::::::::::::", url18)
models18 = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url18),
allow_none=True)
print("models:::::::::::::::::::::::::", models18)
# Open the JSON file and load the data
with open('Tickets0.json', 'r') as file:
data = json.load(file)
for res in data:
# print(res)
description_html = res['helpdesk_ticket']['description_html']
# print("id::::::::", description_html)
helpdesk = models18.execute_kw(db18, uid18, password18, 'helpdesk.ticket',
'search', [[['helpdesk_id', '=', helpdesk_id]]])
print("helpdesk::::::::::::::::", helpdesk)
if helpdesk:
print("in if:::::::::::::::::::::", helpdesk[0])
log_note = "Ticket updated from Freshdesk with Subject"
try:
doc_id = models18.execute_kw(db18, uid18, password18, 'helpdesk.ticket',
'message_post', [[helpdesk[0]], description_html, {}])
print(f"Record updated with ID: {doc_id}")
except Exception as e:
print(f"Error creating record: {e}")
我不知道如何在调用方法时添加帮助台工单的记录 ID。我尝试使用以下方法提供它:-
doc_id = models18.execute_kw(db18, uid18, password18, 'helpdesk.ticket',
'message_post', [helpdesk[0]],[description_html])
但没有用,也搜索了一些帖子,但没有任何作用。
我是否做错了什么或者遗漏了什么?
execute_kw
通常需要 7 个参数:mail.thread.message_post()
(或helpdesk.ticket.message_post()
)只接受一个位置参数(对于外部 API,它是将记录集放入的 idself
),但您的列表中有 3 个。以下应该有效: