Py 3: How to switch application to Unicode strings?

Stephen Hansen apt.shansen at gmail.com
Tue Jan 19 14:56:13 EST 2010


On Tue, Jan 19, 2010 at 7:50 AM, Gnarlodious <gnarlodious at gmail.com> wrote:

> I am using Python 3, getting an error from SQLite:
>
> sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless
> you use a text_factory that can interpret 8-bit bytestrings (like
> text_factory = str). It is highly recommended that you instead just
> switch your application to Unicode strings.
>
> So... how do I switch to Unicode? I thought I was doing it when I put

# coding:utf-8
>
> at the start of my script.
>

All that does is mean that the script itself is encoded as utf8.

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.

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100119/e3c5c884/attachment-0001.html>


More information about the Python-list mailing list