7

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?

Uooo
  • 6,204
  • 8
  • 36
  • 63
sogeking
  • 1,216
  • 2
  • 14
  • 45
  • possible duplication of http://stackoverflow.com/questions/211501/using-sqlite-in-a-python-program – QuestionEverything Sep 03 '13 at 10:02
  • You can [have a look at this too](http://trac.edgewall.org/wiki/PySqlite#DatabaseError:fileisencryptedorisnotadatabase). It seems to be a permission issue or the (path to the ) file does not exist –  Sep 03 '13 at 10:02
  • The file is a real DB, opening it and inserting data from CLI works perfectly. So it's not the same issue. – sogeking Sep 03 '13 at 10:04
  • @FoxMaSk rw rights, I'm the owner of the db file, the NAME_DB is a relative path to the current directory. Definitely the file is there, checking os.path.exists() returns True. – sogeking Sep 03 '13 at 10:11
  • Check whether the downloaded file has the correct contents. It might be possible that you got just an error message, or that your hoster tried to insert ads into the 'web page'. – CL. Sep 03 '13 at 11:10
  • It works...`code`sqlite> insert into log(date, count, average) values (date('now'), 1, 1.2); sqlite> select * from log; 2013-09-03|1|1.2 – sogeking Sep 03 '13 at 11:37

4 Answers4

10

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.

sogeking
  • 1,216
  • 2
  • 14
  • 45
2

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.

0

Okay I faced the same problem and as Visionnaire said Just replace the sqlite3.dll in the pythonXX\DLLs with sqlite3.dll in the CLI sqllite folder which originally contains sqlite3.exe and the problem was solved

QuantumLicht
  • 2,103
  • 3
  • 23
  • 32
Devi Prasad Khatua
  • 1,185
  • 3
  • 11
  • 23
0

I had the same problem, and I thought it's something wrong with the sqlite3 db I was working on. But it appeared, that I've accidentally overrode another sqlite3.db file (that was present in my project), as an ASCII. I was not aware that the error was coming from another db. Pay attention :)

Thedam
  • 51
  • 1
  • 7