views:

159

answers:

2

InstaMapper is a GPS tracking service that updates the device's position more frequently when the device is being tracked live on the InstaMapper webpage. I'd like to have this 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='hunter2')) 
opener.open('http://www.instamapper.com/fe?action=login', params)
if not 'id' in [cookie.name for cookie in cj]:
    raise ValueError, "Login failed"

# 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 to that page. Why isn't cj grabbing the InstaMapper cookie?

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

A: 

action=login is part of the parameters, and should be treated accordingly:

params = urllib.urlencode(dict(action='login', username_hb='user', password_hb='hunter2')) 
opener.open('http://www.instamapper.com/fe', params)

(Also, this particular username/password combination is invalid, I assume, that you actually use a valid username and password in your actual code, otherwise the login fails corretly.)

oefe
adding the action as a parameter solved it; thanks!
Matt Ball
A: 

Have you looked at whether there is a cookie specifically designed to foil your attempts? I suggest using Wireshark or other inspector to see if there is a cookie that changes (via javascript, etc) when you manually log in.

(Ethical note: You may be violating the terms of service and incurring much more cost to the company than you are paying for. I used to run a service like this and every additional/unplanned location update was between $0.01 - $0.05 but I'm sure its come down.)

David W
There don't seem to be any 'foiling cookies' as oefe's suggestion made the fix. Hm, I was wondering about TOS violations..it isn't different than just holding the page open on your own browser all the time though.
Matt Ball