I'm trying to insert a utf-8 string, but I get:
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.
Here is the whole module. Here are relevant parts of code:
########### reading json from a utf-8 file:
with open(file_name) as f:
return json.loads(f.read())
########### feeding utf-8 encoded text to constructor
for obveznik in json:
vlasnici[obveznik["id_obveznik"]] = Vlasnik(obveznik["id_obveznik"], obveznik["naziv"].encode('utf-8'))
########### constructor simply assigns
class Vlasnik
def __init__(self, id, ime):
self._id = id
self._ime = ime
########### here's a getter in the same class:
def ime(self):
return self._ime
########### and then I use the getter
cur.execute("INSERT INTO indeksi VALUES(?, ?, ?, ?, ?, ?)", (
# [...]
vlasnik.ime(),
# [...]
))
########################
I get the sqlite3.ProgrammingError on cur.execute(). I read the string frmo utf-8 file and assigned it to a class field using .encode('utf-8'). What more do I have to do? :-/
Thanks in advance.