After a lot of Google searching, I got my python script to login with Selenium, but now the page is telling me that:

This browser or app may not be secure. Learn more
Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in.

Is there anyway around this? Here is my current script.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(ChromeDriverManager().install())
email = driver.find_element_by_id('identifierId')

actions = ActionChains(driver)

Sending keys directly to the password field wasn't working so I tried sending keys to the browser itself and now I'm getting this error. I don't know how to proceed further.

Edit: Toggling Less secure app access did not work: https://stackoverflow.com/a/59607923/11343425

  • 2
    Why are you logging into Gmail at all? Can't you use their API? – pavelsaman Jan 25 at 7:24
  • 1
    Your code works fine (just add a sleep before sending to password field ) i am not getting any error .could you put the full error and screen shots – PDHide Jan 26 at 1:32
  • @PDHide - "This browser or app may not be secure. Learn more Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in." – SurpriseDog Jan 26 at 13:57

This Google Support page states that sign in via browsers that "Use automation testing frameworks" is being disabled for the following security reasons and Google advices to do "Sign in with Google" using browser-based OAuth 2.0 authentication service.

As some websites, like stackoverflow.com allow you to sign in to their services using "Sign in with Google" it must happen via Google OAuth 2.0 authentication. This implicates that doing so you are also indirectly signing in to your Google account and therefore you can use all the Google services.

So you can fully automatically sign in to your Google account, e.g. by using a Python script, by performing these actions in your code:

  1. Open a new browser window that is controlled by selenium webdriver
  2. In the same window load the StackOverflow login page (or any other site that uses "Sign in with Google")
  3. Choose for "Log in with Google"
  4. Provide your Google account credentials and login to StackOverflow
  5. Load the Google mailbox by opening https://mail.google.com/ or https://www.gmail.com/

This way you land down in your Gmail mailbox without performing any manual actions.

Please remember to add some 5s delays between different actions as doing it too quickly or too frequently can be recognized by StackOverflow as malicious automated actions and you can get blocked and you will need to make the manual I'm not a robot verification

| improve this answer | |
  • 1
    I've moved on in my life since I asked this question in January, but I trust the community here. Have an accept. – SurpriseDog Jun 9 at 12:37
  • I've been trying to solve this for days. This the correct answer! – Dave Shinkle yesterday

Google forbids using automated scripts for logging into Gmail.

To help protect your account, Google doesn’t let you sign in from some browsers. Google might stop sign-ins from browsers that:

  • Don’t support JavaScript or have Javascript turned off.
  • Have unsecure or unsupported extensions added.
  • Use automation testing frameworks.
  • Are embedded in a different application.

See: https://support.google.com/accounts/answer/7675428?hl=en

| improve this answer | |
  1. Open browser which controlled by selenium
  2. Open StackOverflow site manually(or another site which have authorization with google)
  3. Perform authorization with google manually

Then when you run your code again with gmail authorization it should work fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.