Search code examples
pythondocx-mailmerge

mailmerge: What does 'ValueError: Element is not a child of this node' mean?


I'm trying to populate a Word document in Python with docx-mailmerge. Everything was working fine, but after some editing at home on another computer with another version of Word, my script gives an error at the line:

document = MailMerge(template) 

Error:

document = MailMerge(template)

File "C:\Python27\lib\site-packages\mailmerge.py", line 79, in __init__
parent.remove(child)
File "src\lxml\lxml.etree.pyx", line 950, in lxml.etree._Element.remove 
(src\lxml\lxml.etree.c:50327)
ValueError: Element is not a child of this node.

What does this mean?


Solution

  • You didn't give us any run-time context, but this message simply informs you that the object lmxl.etree at the given line, has no attribute (data field) called Element. etree apparently exists, but it obviously is not of the expected type or structure. It's possible that the tree node isn't fully-formed somehow: a spreadsheet cell is empty, or has a seriously invalid value.