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

674 views Asked by At

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?

2

There are 2 answers

0
Prune On BEST ANSWER

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.

0
Hiillostaja On

I had similar problem with docx-mailmerge. It turned out that in my .docx file curly brackets on a single mergefield were not at the same row, so mailmerge could not detect the merge field properly.

Example: { MERGEFIELD Foo                                                                   }

Fixed: { MERGEFIELD Foo }