sqlite3.OperationalError: unable to open database file

# -*- coding:utf-8 -*-  

'''
Created on 2016年1月12日
@author: Lux
'''

import sqlite3

chromeHistoryDbPath = '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
  • 对数据库文件要有读写的权限;
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值