Python sqlite3.DatabaseError:文件已加密或不是数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18589280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:09:58  来源:igfitidea点击:

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

pythonsqlite

提问by sogeking

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

我创建了一个 sqlite 数据库并将其上传到托管。

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

然后我从我的脚本中检索它并尝试插入一些数据,但是 execute() 正在返回一个

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

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?

如果我使用 sqlite CLI 插入数据,则不会发生此类错误。请你帮助我好吗?

采纳答案by sogeking

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 -versionreturns 2.8.17, while the python version is 2.7.3.

sqlite CLI 和 python sqlite API 之间的版本不匹配?我从脚本而不是 CLI 再次创建了我的数据库。现在从脚本插入和选择工作,而不是从 CLI。$sqlite -version返回 2.8.17,而 python 版本是 2.7.3。

回答by Visionnaire

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 :

我在使用 SQLite3 库由 C++ 代码创建的数据库中遇到了同样的问题,该库后来被 SQLite3 的 Python 2.7 版本访问。我无法在 Python 脚本中查询数据库。为了解决我电脑上的问题,我更改了以下版本:

C:\Python27\DLLs\sqlite3.dll

C:\Python27\DLLs\sqlite3.dll

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

对于在 C++ Sqlite 库目录中找到的版本。

回答by wolframalpha

Okay I faced the same problem and as Visionnaire said Just replace the sqlite3.dllin the pythonXX\DLLswith sqlite3.dllin the CLI sqllitefolder which originally contains sqlite3.exeand the problem was solved

好吧,我面临着同样的问题,作为VISIONNAIRE说只需更换sqlite3.dllpythonXX\DLLssqlite3.dll在CLIsqllite原本包含的文件夹sqlite3.exe,问题就解决了

回答by Thedam

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 :)

我遇到了同样的问题,我认为我正在处理的 sqlite3 db 有问题。但看起来,我不小心将另一个 sqlite3.db 文件(存在于我的项目中)作为 ASCII 覆盖。我不知道错误来自另一个数据库。请注意 :)