xml.etree.ElementTree使用報錯"cannot serialize %r (type %s)" % (text, type(text).__name__)

python使用xml時報錯如下:

"cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize 512 (type int)

這裏的512是我報錯xml,etree.ElementTree.SubElement().text添加text內容時這裏爲數字512,這種報錯是因爲xml的text內容應該爲字符串,添加數字序列化報錯,將所有的數字改爲字符字符串形式即可

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章