python - sqlite3.数据库错误: file is encrypted or is not a database

标签 python sqlite

我已经创建了一个 sqlite 数据库并将其上传到主机。

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

DatabaseError(文件已加密或不是数据库)。

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

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

最佳答案

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

关于python - sqlite3.数据库错误: file is encrypted or is not a database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589280/

相关文章:

python - SQLite 和 Python。值写入没有错误,但程序终止后不在数据库中

python - 使用 sklearn count vectorizer 获取 n gram 后缀

android - 定期更新后台数据(Android)

android - 用于 Android 应用程序 (Qt) 的嵌入式 SQLite 数据库

python - 在Python模块中调用C头文件函数

python - PyQt - 重新实现 QSqlTableModel 数据方法时出现问题

python - Flask - SocketIO 隐藏在 Nginx 反向代理后面

android - rawQuery 在 SQLite android 中不起作用

laravel - sqlite连接使用用户名和密码

Android 全局 SQLite 数据库访问