What is the cause of a Stack usage error from libxml2/libxslt/lxml?
It seems that you're using lxml extension functions. In this case, the "Stack usage error" (XPATH_STACK_ERROR internally) happens when a value is popped off the XPath stack and the stack is empty. The typical scenario is an extension function called with fewer parameters than expected.
libxml: "Stack usage error" - further information?