Friday, October 2, 2009

Python - Fixes to the Google Login script

Just recently Google changed some things behind the scenes to their login page. More specifically, on the login page there is now a hidden form element called "GALX", the value of which must be passed along with the Username and Password when signing in - other wise, the sign in fails. This affected a few of my scripts, most notably my Google Voice Mass Contact script which a few visitors let me know about.

I modified the scripts that are contained in that post to work with the new system. So, if you have been having trouble with the mass contact script, go to that post and re-download the scripts.

Here is the complete login script, including how to get the _rnr_se value after logging in.

import urllib
import urllib2
import getpass
import re

email = raw_input("Enter your Google username: ")
password = getpass.getpass("Enter your password: ")

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())

# Define URLs
loing_page_url = ''
authenticate_url = ''
gv_home_page_url = ''

# Load sign in page
login_page_contents =

# Find GALX value
galx_match_obj ='name="GALX"\s*value="([^"]+)"', login_page_contents, re.IGNORECASE)

galx_value = if is not None else ''

# Set up login credentials
login_params = urllib.urlencode( {
'Email' : email,
'Passwd' : password,
'continue' : '',
'GALX': galx_value

# Login, login_params)

# Open GV home page
gv_home_page_contents =

# Fine _rnr_se value
key ='name="_rnr_se".*?value="(.*?)"', gv_home_page_contents)

if not key:
logged_in = False
print 'Failed!'
logged_in = True
key =
print 'Success!'
blog comments powered by Disqus