Error trying to access firefox cookies using python -


hi working on using firefox cookies in python. referred this. getting "databaseerror: file encrypted or not database" error. have gone through other answers , seem suggest compatibility issue none of them details how away issue.

os: windows 7, firefox version: 38, python: 2.7.9.

please me fix issue. below code. btw have copy of 'cookies.sqlite' in working directory, don't bother answering path incorrect.

thanks.

import urllib2 import cookielib sqlite3 import dbapi2  host = 'www.reddit.com' ff_cookie_file= 'cookies.sqlite'  file = open("cookie.txt", "w") file.write("#lwp-cookies-2.0\n") match = '%%%s%%' % host con = dbapi2.connect(ff_cookie_file) cur = con.cursor() cur.execute("select name, value, path, host moz_cookies host ?", [match]) item in cur.fetchall():     cookie = "set-cookie3: %s=\"%s\"; path=\"%s\";  \     domain=\"%s\"; expires=\"2038-01-01 00:00:00z\"; version=0\n" % (item[0], item[1], item[2], item[3]) file.write(cookie) file.close()  cj = cookielib.lwpcookiejar() cj.load("cookie.txt")  opener = urllib2.build_opener(urllib2.httpcookieprocessor(cj)) urllib2.install_opener(opener) 

edit: running command "sqlite3 cookies.sqlite" gives following output:

python: can't open file 'sqlite3': [errno 2] no such file or directory 

i guess reason system has no file "sqlite3.exe".

for further confirmation whether or not sqlite3 works, created db, inserted few values , queried it. worked charm. here link. guess there problem "cookies.sqlite" file. other way around make work. guys please need solve problem.

your code more or less works me:

$ python python 2.7.6 (default, sep  9 2014, 15:04:36) [gcc 4.2.1 compatible apple llvm 6.0 (clang-600.0.39)] on darwin type "help", "copyright", "credits" or "license" more information. >>> sqlite3 import dbapi2 >>> con = dbapi2.connect('cookies.sqlite') >>> cur = con.cursor() >>> cur.execute("select name, value, path, host moz_cookies host ?", ["%%www.reddit.com%%"]) <sqlite3.cursor object @ 0x10bbb3030> >>> item in cur.fetchall(): ...     print item[0] ... loid loidcreated loid loidcreated 

maybe file corrupt? can try opening sqlite3 directly?

$ sqlite3 cookies.sqlite sqlite version 3.8.5 2014-08-15 22:37:57 enter ".help" usage hints. sqlite> select name moz_cookies host "%%www.reddit.com%%"; loid loid loidcreated loidcreated 

Comments