Just in case, change `pass` to `data = lxml.html.tostring(document, encoding='unicode')` as a backup solution.