首页 > 代码库 > SQLAlchemy解决ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory

SQLAlchemy解决ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory

SQLAlchemy 报ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings错误

python2.x中最讨厌的就是编码问题了,写下来以备后用。

解决方法:

1.开头加上:

#encoding:  utf-8


 2.尝试把字符转化为unicode格式

unicode( str_name )

这种方法有时会出现:“UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128 ...” 这种问题。

解决方法:

import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)


SQLAlchemy解决ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory