Get Google Account AuthToken using Python

 import urllib, urllib2

#
# get an AuthToken from Google accounts
#
auth_uri = ‘https://www.google.com/accounts/ClientLogin
authreq_data = urllib.urlencode({ "Email":   users_email_address,
                                  "Passwd":  users_password,
                                  "service": "ah",
                                  "source":  my_app_name,
                                  "accountType": "HOSTED_OR_GOOGLE" })

headers={}

headers["Content-type"] = "application/x-www-form-urlencoded;charset=UTF-8"
auth_req = urllib2.Request(auth_uri, data=authreq_data, headers=headers)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_body = auth_resp.read()
# auth response includes several fields - we’re interested in
#  the bit after Auth=
auth_resp_dict = dict(x.split("=")
                      for x in auth_resp_body.split("n") if x)
authtoken = auth_resp_dict["Auth"]

print authtoken