title: Error trying to access firefox cookies using python
body: <p>Hi I am working on using firefox cookies in python. I referred <a href="http://krosinski.blogspot.in/2012/07/make-websites-recognise-pythonurllias.html" rel="nofollow">this</a>. I am getting "DatabaseError: file is encrypted or is not a database" error. I have gone through other answers too and they seem to suggest compatibility issue but none of them details how to do away the issue. </p>
  
  <p>OS: windows 7, Firefox version: 38, Python: 2.7.9.</p>
  
  <p>Please help me fix this issue. 
  Below is the code. BTW I have copy of 'cookies.sqlite' in my working directory, so don't bother answering my path is incorrect.</p>
  
  <p>Thanks.</p>
  
  <pre><code>import urllib2
  import cookielib
  from 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 from moz_cookies where host like ?", [match])
  for 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)
  </code></pre>
  
  <p>Edit: running the command "sqlite3 cookies.sqlite" gives the following output:</p>
  
  <pre><code>python: can't open file 'sqlite3': [Errno 2] No such file or directory
  </code></pre>
  
  <p>I guess reason for this is that my system has no file as "sqlite3.exe".</p>
  
  <p>For further confirmation about whether or not my sqlite3 works, I created the db, inserted few values and queried it. It worked like charm. <a href="http://www.blog.pythonlibrary.org/2012/07/18/python-a-simple-step-by-step-sqlite-tutorial/" rel="nofollow">here is the link</a>. So I guess there is a problem with "cookies.sqlite" file. Any other way around to make it work. Guys please I really need to solve this problem.</p>