开发者

How do I get a µ character out of sqlite and onto a web-page?

开发者 https://www.devze.com 2022-12-17 23:52 出处:网络
On a Python driven web app using a sqlite datastore I had this error: Could not decode to UTF-8 column

On a Python driven web app using a sqlite datastore I had this error:

Could not decode to UTF-8 column 'name' with text '300µL-10-10'

开发者_开发知识库

Reading here it looks like I need to switch my text-factory to str and get bytestrings but when I do this my html output looks like this:

300�L-10-10

I do have my content-type set as:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />


Unfortunately, the data in your datastore is not encoded as UTF-8; instead, it's probably either latin-1 or cp1252. To decode it automatically, try setting Connection.text_factory to your own function:

def convert_string(s):
    try:
        u = s.decode("utf-8")
    except UnicodeDecodeError:
        u = s.decode("cp1252")
    return u

conn.text_factory = convert_string
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号