[Tutor] cookielib and form authentication woes

Matt Ball mab43 at duke.edu
Sat Jan 9 16:31:56 CET 2010


dear tutors,

I'm trying to use a GPS tracking service called InstaMapper.  The service
changes how frequently it updates the tracking device's position based on
whether the UI is being accessed on the InstaMapper webpage.  I'd like to
have the increased update frequency happen all the time so I thought I'd
write a python script to login to my account and access the page
periodically:

import urllib2, urllib, cookielib

cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

params = urllib.urlencode(dict(username_hb='user', password_hb='resu'))
opener.open('http://www.instamapper.com/fe?action=login', params)
if not 'id' in [cookie.name for cookie in cj]:
    raise ValueError, "Login failed"

# now try secured page
resp = opener.open('http://www.instamapper.com/fe?page=track&device_key=abc
')
print resp.read()
resp.close()

The ValueError is raised each time. If I remove this and read the response,
the page thinks I have disabled cookies and blocks access. Why isn't cj
grabbing the InstaMapper cookie?

Are there better ways to make the tracking service think I'm viewing my
account constantly?

-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100109/d7ae2416/attachment-0001.htm>


More information about the Tutor mailing list