When backing up my database in Sqlite3 , the Python interpreter returns the following message:
TypeError: must be unicode, not str
on line f.write("%s\n" % linha)
, I could not find a solution for this error.
Follow the code:
#coding: utf-8
__author__ = 'Dener Carvalho'
import sqlite3
import io
#Conecta ao banco
conn = sqlite3.connect('clientes.db')
with io.open('clientes_dump.sql', 'w') as f:
for linha in conn.iterdump():
f.write("%s\n" % linha)
print 'Backup efetuado com sucesso.'
print 'Salvo como clientes_dump.sql'
conn.close()