title: Logging into Google account with Python requests
body: <p>On multiple login pages, a google login is required in order to proceed. I would like to use <code>requests</code> library in python in order to log myself in. Normally this would be easy with the <code>requests</code> library, however I have not been able to get it to work. I am not sure if this is due to some restriction Google has made (perhaps I need to use their API?), or if it is because the Google login page requires the user to enter their email first, then press submit, and then enter their password, etc.</p>
  
  <p>This problem has been asked before over here, but none of the solutions work for me. Currently I've been using code provided in this solution: <a href="https://stackoverflow.com/questions/39540479/log-into-google-account-using-python">Log into Google account using Python?</a> as shown here:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import requests
  
  my_email = "email_placeholder@gmail.com" # my email is here
  my_pass = "my_password" # my password is here
  
  form_data={'Email': my_email, 'Passwd': my_pass}
  post = "https://accounts.google.com/signin/challenge/sl/password"
  
  with requests.Session() as s:
      soup = BeautifulSoup(s.get("https://mail.google.com").text, "html.parser")
      for inp in soup.select("#gaia_loginform input[name]"):
          if inp["name"] not in form_data:
              form_data[inp["name"]] = inp["value"]
      s.post(post, form_data)
      html = s.get("https://mail.google.com/mail/u/0/#inbox").content
  
      print(my_email in s.get('https://mail.google.com/mail/u/0/#inbox').text) # Prints 'False', should print 'True'
  </code></pre>
  
  <p>As you can see the code at the end returns <code>False</code>. Furthermore, if I write the html to a file and open that in a browser, the page I get is the default Google login page indicating it has not worked.</p>