472,145 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

RE: SQLite and Python 2.4

Thanks Guilherme. That helped. I guess I was thinking that pysqlite would
automatically come with some version of sqlite. The fact that it doesn't is
what was causing me to get the strange results.

I downloaded the Windows version of the SQLite3.dll. I didn't know where to
put it so I first put it in its own directory and tried to register it.
That didn't work so I just moved it to the pysqlite directory in
site-packages. That did the trick.

It took way longer than I thought to figure out how this stuff worked.
Here's an example putting it all together. It's Windows specific but only
for the part that finds where the cookies.sqlite file is. Maybe it will
save someone else the time.

import ConfigParser
from pysqlite2 import dbapi2 as sqlite
import os

def GetFirefoxCookies(domain, d):

"""This function gets all FireFox 3 cookies for the passed in domain and
adds them to the dict object"""

# Get the Firefox data path
FireFoxPath = os.environ['AppData'] + '\Mozilla\Firefox'

# use the FireFoxPath to load up the profies.ini file
iniFileName = r'%s%s' % (FireFoxPath, r'\profiles.ini')

# use the ConfigParser module to load in the contents of the ini file
parser = ConfigParser.ConfigParser()

# I'm just getting the path from the [Profile0] section since this code
# is only running on my system. For a production system, you'd probably
# want to look for the section with "default=1".
path = parser.get('Profile0','Path')

# with all that, we can finally find the cookies.sqlite file
dbfile = '%s\%s\%s' % (FireFoxPath, path.replace('/','\\'),

# Next create an sqlite connection object and load up the cookies table
conn = sqlite.connect(dbfile)

# get a cursor object
c = conn.cursor()

# get the name and cookie values
c.execute("SELECT name, value FROM moz_cookies WHERE host = '%s'" %

# loop through the cookies and add their key and values to the
# dictionary.
for row in c.fetchall():
d[row[0].encode('utf-8')] = row[1].encode('utf-8')

if __name__ == '__main__':

domain = 'localhost'
cookiedict = {}
GetFirefoxCookies(domain, cookiedict)
print cookiedict
-----Original Message-----
From: Guilherme Polo [mailto:gg****@gmail.com]
Sent: Tuesday, July 01, 2008 6:15 PM
To: jo*@goldthwaites.com; py*********@python.org
Subject: Re: SQLite and Python 2.4

On Tue, Jul 1, 2008 at 9:51 PM, Joe Goldthwaite <jo*@goldthwaites.com>
I'm confused. (Not a new experience). I've got a web application running
under Zope. I use the Wing IDE for testing and debugging. When trying to
recreate problems that come up on the web, I wrote some little routines
pull my cookies out of the Firefox cookies.txt file into my code. That
I'm working with all the same options under Wing that my app uses when
running under Zope.

That's worked great until I upgraded to Firefox 3. Firefox 3 moved their
cookies from cookies.txt to cookies.sqlite. I haven't worked with SQLite
all so I started searching for examples and found this;

import sqlite3
conn = sqlite3.connect('test.db')
c = conn.cursor()
rows = c.execute('SELECT * from somefile')

Looks simple enough but I can't get it to work. Here are my questions;

1. How do you get sqlite3 for Python 2.4? I can't find it anywhere.
You need sqlite itself (www.sqlite.org) and bindings, pysqlite 2
(http://oss.itsystementwicklung.de/trac/pysqlite/) or aspw
2. If sqlite3 is only for Python 2.5, does sqlite2 work the same way?
You are confused, yes. The sqlite3 package that comes with python2.5
is actually pysqlite2, which interfaces with sqlite3.
Also, sqlite3 and sqlite2 files format are not compatible.
3. Looking at the cookies.sqlite file, I see some text right at the top
"SQLite format 3". Does that mean that I need to use sqlite3?
I kind of got the above example using pysqlite2.4.1 for python 2.4. I get
through the part where I create the connection object but the resulting
object doesn't have a cursor method. I thought that maybe it wasn't
recognizing the cookies.sqlite file as a SQLite database so I tried the
code giving it a junk text file instead and it behaved the same way.
I didn't get an error message, I'm thinking that I've got the wrong
for the Firefox cookies.sqlite file.

I don't have a clue as to where else to look to trace it down. I'm hoping
that someone here is more familiar with it and can give me some pointers.


Joe Goldthwaite


-- Guilherme H. Polo Goncalves

Jul 3 '08 #1
0 2466

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by John Salerno | last post: by
14 posts views Thread by 7stud | last post: by
3 posts views Thread by ricardo.turpino | last post: by
1 post views Thread by mikhail.savitsky | last post: by
3 posts views Thread by kyosohma | last post: by
2 posts views Thread by Joe Goldthwaite | last post: by
reply views Thread by Guilherme Polo | last post: by
20 posts views Thread by timotoole | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.