Don't crash on weird character encodings

Expecting SQLite columns to all be valid utf8 doesn't work, because we are
deailing with all kinds of databases. Instead, we now use the 'replace'
encoding mode to replace any non-UTF8 characters with a [X] character.
pull/383/head
Simon Willison 2017-10-24 17:01:34 -07:00
rodzic c371f06fde
commit 4c7379a898
1 zmienionych plików z 2 dodań i 1 usunięć

3
app.py
Wyświetl plik

@ -34,6 +34,7 @@ def get_conn(name):
uri=True
)
conns[name].row_factory = sqlite3.Row
conns[name].text_factory = lambda x: str(x, 'utf-8', 'replace')
return conns[name]
@ -279,7 +280,7 @@ def pks_for_table(conn, table):
if row[-1]
]
rows.sort(key=lambda row: row[-1])
return [r[1] for r in rows]
return [str(r[1]) for r in rows]
def path_from_row_pks(row, pks):