[Tutor] html2text expects bytes-like object
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Nov 8 13:31:16 EST 2021
On 08/11/2021 13:33, Julius Hamilton wrote:
> html2text.html2text(html)
>
> But this returns:
>
> TypeError: a bytes-like object is required, not 'str'
So try converting html to bytes:
> html2text.html2text(bytes(html,encoding='utf8'))
> In the documentation, it shows the above html2text method working for what
> appears to be a string.
Strings and bytes are easily confused visually.
> Why am I getting the response that I need to pass it a "bytes-like object"?
Probably because that's what it needs. A lot of low
level C library functions require a bytes object
rather than a {Python Unicode string. So, if the module
uses such functions, it probably wants a bytes object
passed to it.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list