'chrome history db access is locked

I am creating an application where I need to access chrome's history but whenever i try to connect with that history db i get the following error:
c.execute(sql) sqlite3.OperationalError: database is locked

here is the code:

 `data_path = os.path.expanduser('~')+"/AppData/Local/Google/Chrome/User Data/Default"
files = os.listdir(data_path)
history_db = os.path.join(data_path, 'history')
conn = sqlite3.connect(history_db)
c = conn.cursor()
sql = "SELECT url FROM urls"
c.execute(sql)`


Solution 1:[1]

Another way around this if you dont want to close your browser is to simply copy the history data into new location and then read it. here is the code:

import sqlite3
import shutil

source_file = 'C:\\Users\\{username}\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History'
destination_file = 'C:\\Users\\{username}\\Downloads\\History'

time.sleep(30)# wait to update the history file
shutil.copy(source_file,destination_file)
con = sqlite3.connect('C:\\Users\\{username}\\Downloads\\History')
cursor = con.execute("SELECT * FROM urls")

Now you can see the Chrom browser history without closing your Chrom Browser.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shahin Shirazi