好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ProgrammingError: You must not use 8bit bytestring

ProgrammingError: You must not use 8bit bytestrings unless you use a text_factory that can interpret 8bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings

这个问题只在  
Python 2.6/sqlite3 或者 Python 3.x中出现

我在Debian Squeeze中默认使用 Python 2.5 就没事
在 Ubuntu 10.04 中使用Python 2.6 就有这个问题

在Django中是这么修复的

if Database.version_info >= (2,4,1):
# Starting in 2.4.1, the str type is not accepted anymore, therefore,
# we convert all str objects to Unicode
# As registering a adapter for a primitive type causes a small
# slow-down, this adapter is only registered for sqlite3 versions
# needing it.
Database.register_adapter(str, lambda s:s.decode(‘utf-8′))

In Py3, anything you do “this” or use str(), you are using unicode strings.

The problem appears to be that you are passing bytestrings to sqlite; things
created with b”this” or bytes(), or read from a file as bytes and not
decoded before passing it to the database.

To really help further, you should provide the line that threw that warning
and show where any variables in it come from. As for that error message, I
believe it means text_factory = bytes.

查看更多关于ProgrammingError: You must not use 8bit bytestring的详细内容...

  阅读:41次

上一篇: python for else statement test

下一篇:py za