sqlite3.OperationalError: unable to open database file

来源:互联网 发布:数据精灵后台授权 编辑:程序博客网 时间:2024/04/29 01:25
# -*- coding:utf-8 -*-  '''Created on 2016年1月12日@author: Lux'''import sqlite3chromeHistoryDbPath = 'C:\Users\Lux\Desktop\History'class GetDbContent():    def __init__(self,path):        self.dbpath = path    def ReadTable(self):        con = sqlite3.connect(self.dbpath)        cur = con.cursor()        tableList = cur.execute("select name from sqlite_master where type = 'table' order by name").fetchall()        for table in tableList:            print table[0]        cur.close()if __name__ == '__main__':    a = GetDbContent(chromeHistoryDbPath)    a.ReadTable()

使用python连接sqlite数据库的文件的时候,不小心出现了错误

sqlite3.OperationalError: unable to open database file

百度了一下,错误有许多种,这里稍微列举一些

  • 数据库路径最好写成绝对路径,并且目录要存在,而且 对目录要有读写的权限, 因为打开数据库的时候,会产生临时数据;
  • 在Win 7 enterprise 和 Win Xp Pro上面写python v2.7时, 'C:\Users\Lux\Desktop\History' 路径 有时候要写成 'C:\\Users\\Lux\\Desktop\\History'
  • 有种情况我也是无法解释的,某些时候你的数据库文件后缀名不是 db 也不行,需要改名为 xxx.db
  • 对数据库文件要有读写的权限;
0 0
原创粉丝点击