def test_login():
    username = ''
password = ''
cookie_jar = cookielib.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
login_dict = urllib.parse.urlencode({'username': username, 'password': password})
opener.open('https://accounts.google.com/ServiceLogin', login_dict)
response = opener.open('https://plus.google.com/explore')
print(response.read())
if __name__ == '__main__':
    test_login()
Logging in to google using python?