ValueError: dictionary update sequence element #0 has length 1; 2 is required

from docxtpl import DocxTemplate

doc = DocxTemplate("template.docx")
context = { 'name' :name, 'surname':surname, 'adress':adress,'phonenumber':phonenumber,'marital_status':marital_status,'Date_of_birth':Date_of_birth,'Objective':Objective,'education':education,'qualifications':qualifications,'work_exp':work_exp,'personal_qualities':personal_qualities, 'e_mail':e_mail }
doc.render("context")
doc.save("C:\scripts\CV.docx")

При попытке запуска выдаёт ошибку:

ValueError: dictionary update sequence element #0 has length 1; 2 is required


Ответы (2 шт):

Автор решения: Zhihar

может так:

doc.save("C:\\scripts\\CV.docx")
→ Ссылка
Автор решения: MaxU

замените:

doc.render("context")

на

doc.render(context)

вы передаете строковой литерал (строку: "context"), вместо ожидаемого словаря.


Причина возникновения данной ошибки: скорее всего в функции doc.render() происходит попытка объединить другой словарь со словарем, переданным в качестве первого аргумента.

Воспроизведение ошибки:

d = {"a": 1}
d.update("context")

выдает:

ValueError: dictionary update sequence element #0 has length 1; 2 is required
→ Ссылка