旧それなりブログの跡地、画像やスタイルやJSなどが壊れてることがあります。

Unicode strings with encoding declaration are not supported

2012年11月21日

Pythonのlxmlライブラリの以下のエラーについてです
検索しても日本語記事が無かったので書いておきます

ValueError: Unicode strings with encoding declaration are not supported.

解析対象をUnicode型ではなく文字列型で渡す

lxmlドキュメントの該当部分に解答があります

Similarly, you will get errors when you try the same with HTML data in a unicode string that specifies a charset in a meta tag of the header. You should generally avoid converting XML/HTML data to unicode before passing it into the parsers. It is both slower and error prone.

metaタグにcharset設定があるHTMLデータをユニコードで渡した場合はエラーになるよ。
XML/HTMLデータをパーサに投げる前にユニコードに変換することは普通避けた方がいいよ。
それは遅いしエラーになり易いよ。

「charsetの文字コードを使うからUnicode型ではなくて文字列で渡して下さい」
ということのようです

もしcharsetが誤ってるなら、多分オプションとかがあるんじゃないかなぁ?