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?
The sqlite3. connect() function returns a Connection object that we will use to interact with the SQLite database held in the file aquarium.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With