ich hänge gerade beim leidigen Thema Umlaute fest. Ich habe zwei Scripte (Programme). Das eine liest eine CSV-Datei aus und schreibt die Daten in eine Sqlite-DB.
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
...
# CSV-Import
with open(csvfile, 'rb') as csvfile:
data = csv.reader(csvfile, delimiter=';')
for row in data:
cur.execute("INSERT INTO users (name,first_name,email,hash) VALUES (?,?,?,0)", (buffer(row[0]), buffer(row[1]), buffer(row[2])))
con.commit()
In einem anderen Programm sollen die Daten aus der Datenbank gelesen werden.
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
...
@app.route('/status/all')
def show_users_trainings_all(db):
results = db.execute("""select u.name, u.first_name, t.name, ut.completed
from users_trainings as ut
join users as u on ut.U_ID = u.ID
join trainings as t on ut.T_ID = t.ID""").fetchall()
return template('show_users_trainings_all', results=results)
Wie gehe ich am besten mit Umlauten um, damit ich sie ohne Probleme in Sqlite schreiben, lesen und verarbeiten kann?Traceback (most recent call last):
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 862, in _handle
return route.call(**args)
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 1729, in wrapper
rv = callback(*a, **ka)
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle_sqlite.py", line 87, in wrapper
rv = callback(*args, **kwargs)
File "app.py", line 41, in show_users_trainings_all
return template('show_users_trainings_all', results=results)
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 3592, in template
return TEMPLATES[tplid].render(kwargs)
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 3396, in render
self.execute(stdout, env)
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 3383, in execute
eval(self.co, env)
File "/home/patrick/Dropbox/Coding/wbt-bottle/views/show_users_trainings_all.tpl", line 23, in <module>
<td>{{ result[0] }}</td>
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 3334, in <lambda>
self._escape = lambda x: escape_func(touni(x, enc))
File "/home/patrick/Dropbox/Coding/wbt-bottle/bottle.py", line 123, in touni
return s.decode(enc, err) if isinstance(s, bytes) else unicode(s)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)