Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite3.DatabaseError: file is encrypted or is not a database

Tags:

python

sqlite

I have created a sqlite db and uploaded it to a hosting.

Then I'm retrieving it from my script and trying to insert some data, but execute() is returning a

DatabaseError (file is encrypted or is not a database).

urllib.urlretrieve('http://%s/%s' % (HOST, NAME_DB), NAME_DB)
con = sqlite3.connect(NAME_DB)
cur = con.cursor()
cur.execute('insert into log(date, count, average) values(date("now"), ?, ?)', (1, 1.2))
con.commit()
con.close()

Traceback (most recent call last):
  File "mylog.py", line 17, in <module>
    cur.execute('insert into log(date, count, average) values(date("now"), ?, ?)', (1, 1.2)) 
sqlite3.DatabaseError: file is encrypted or is not a database

Such error doesn't happen if I use the sqlite CLI to insert data. Could you please help me?

like image 721
sogeking Avatar asked Sep 03 '13 09:09

sogeking


People also ask

What does sqlite3 connect return?

The sqlite3. connect() function returns a Connection object that we will use to interact with the SQLite database held in the file aquarium.

What happens if you don't close SQLite connection?

If there is no outstanding transaction open then nothing happens. This means you do not need to worry too much about always closing the database before process exit, and that you should pay attention to transactions making sure to start them and commit at appropriate points.

What is SQLite used for?

SQLite is often used as the on-disk file format for desktop applications such as version control systems, financial analysis tools, media cataloging and editing suites, CAD packages, record keeping programs, and so forth. The traditional File/Open operation calls sqlite3_open() to attach to the database file.


2 Answers

Version mismatch between sqlite CLI and python sqlite API? I created again my db from the script instead of the CLI. Now insert and select work from the script, but not from the CLI. $sqlite -version returns 2.8.17, while the python version is 2.7.3.

like image 153
sogeking Avatar answered Sep 30 '22 04:09

sogeking


I had the same problem with a database created by C++ code using SQLite3 library which was later accessed by Python 2.7 version of SQLite3. I was unable to query the database in Python scripts. To solve the problem on my computer, I changed the version of :

C:\Python27\DLLs\sqlite3.dll

for the version found in C++ Sqlite library directory.

like image 42
Visionnaire Avatar answered Sep 30 '22 03:09

Visionnaire