can't serialize empty HTML: TypeError: expected string or bytes-like object

Bug #1969937 reported by Jakub Wilk
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
New
Undecided
Unassigned

Bug Description

Apparently lxml.html.parse() can create completely empty tree;
but if you run lxml.html.tostring() on such a tree, it fails with an unhelpful error message:

    >>> doc = lxml.html.parse(open('/dev/null'))
    >>> lxml.html.tostring(doc)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File ".../lib/python3.8/site-packages/lxml/html/__init__.py", line 1873, in tostring
        html = __bytes_replace_meta_content_type(bytes(), html)
    TypeError: expected string or bytes-like object

Version information:

Python : sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)
lxml.etree : (4, 8, 0, 0)
libxml used : (2, 9, 12)
libxml compiled : (2, 9, 12)
libxslt used : (1, 1, 34)
libxslt compiled : (1, 1, 34)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.