Python unicode Decode Error SUDs

前端 未结 1 1082
遥遥无期
遥遥无期 2021-01-21 09:13

OK so I have # -*- coding: utf-8 -*- at the top of my script and it worked for being able to pull data from the database that had funny chars(Ñ ,Õ,é,—,–,’,…) in it

相关标签:
1条回答
  • 2021-01-21 09:42

    #-*- coding: xxx -*- has nothing to do with this error, it only applies to the encoding of the source file it is declared in, not the content of variables coming from a database.

    Your error says that you try to pass a str type object containing non ASCII characters to the unicode() constructor (which is called at line 43 of suds/sax/text.py).

    You have to convert the strings coming from the database to unicode objects ; for example if your database is encoded in UTF-8:

    title = product[1].decode("UTF-8")
    

    See the str.decode() documentation for details.

    0 讨论(0)
提交回复
热议问题