0

I am trying to create a script that will login to my google slide presentations and update them. In order to do this with Selenium it appears I have to login each time which causes the 'This browser or app may not be secure' error page, shown below.

enter image description here

I researched online that you should be able to work around this by logging in through stackoverflow or another site that uses 'log in with google'. However my below attempt seems to still provide the same results. Following up on this, I wasn't able to find out if this is still doable or if this approach no longer works.

Could someone confirm if my approach is outdated or if there is something I've failed to grasp from my approach? Sorry if I've missed something basic, I've just started writing Python so I'm deep in the learning curve stage.

I'm using Ubuntu 20.04 if that's of any use.

Code

#!/usr/bin/env python3

import webbrowser
import pyautogui
import time
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

driver=webdriver.Firefox()
driver.implicitly_wait(30)


url='https://accounts.google.com/o/oauth2/auth/identifier?client_id=717762328687-iludtf96g1hinl76e4lc1b9a82g457nn.apps.googleusercontent.com&scope=profile%20email&redirect_uri=https%3A%2F%2Fstackauth.com%2Fauth%2Foauth2%2Fgoogle&state=%7B%22sid%22%3A1%2C%22st%22%3A%2259%3A3%3Abbc%2C16%3A7667a52eee989fc7%2C10%3A1611306467%2C16%3Ad5e975ab3e71c656%2Cb45db9f242e90237a65d3c06754d76a1f8a7bbfc93dffe8b19376a3a573f700e%22%2C%22cdl%22%3Anull%2C%22cid%22%3A%22717762328687-iludtf96g1hinl76e4lc1b9a82g457nn.apps.googleusercontent.com%22%2C%22k%22%3A%22Google%22%2C%22ses%22%3A%22451ca6a7a6c349248b04db280731cf23%22%7D&response_type=code&flowName=GeneralOAuthFlow'
driver.get(url)

username = driver.find_element_by_id("identifierId")
username.send_keys("fake.user@gmail.com")
my_btn = driver.find_element_by_id('identifierNext')
my_btn.click()
El_Birdo
  • 315
  • 4
  • 19
  • Have you turned off [less secure apps](https://myaccount.google.com/lesssecureapps) on your email? – Insula Jan 22 '21 at 09:25
  • @Insula I hadn't but turning on less secure apps hasn't changed the outcome I'm afraid – El_Birdo Jan 22 '21 at 09:37
  • can you please edit your question and add the error code you are getting, please. – Insula Jan 22 '21 at 09:48
  • @Insula more of a page than an error code. But I've updated the question to reflect what I see – El_Birdo Jan 22 '21 at 10:08
  • If enabling "less secure apps" does not solve your issue, then it may be an outdated chrome version. Update your chrome version and be sure to update your chrome driver for selenium as well. – Insula Jan 22 '21 at 10:22
  • I'm using firefox 84.0.2 which my machine considers the most up to date and selenium 3.141.0 which appears to be the most recent for python – El_Birdo Jan 22 '21 at 10:50

2 Answers2

0

This is because automation testing frameworks are disabled by Google for security reasons However, there are a few things you can do:

  1. The easiest way: Open browser controlled by selenium, open stack overflow and perform authorisation manually. When you next run the script, it will log you in automatically.

  2. Add arguments to the script that block web security:

    from selenium.webdriver.firefox.options import Options
    options = FirefoxOptions()
    options.add_argument('--disable-web-security')
    options.add_argument('--user-data-dir')
    options.add_argument('--allow-running-insecure-content')
    

    You can also do this in the terminal.

  3. Login to stackoverflow with your google account, once logged in go to your email.

    driver.get("https://accounts.google.com/signin/oauth/identifier?client_id=717762328687-iludtf96g1hinl76e4lc1b9a82g457nn."
         + "apps.googleusercontent.com&scope=profile%20email&redirect_uri=https%3A%2F%2Fstackauth"
         + ".com.com%2Fauth%2Foauth2%2Fgoogle&state=%7B%22sid%22%3A1%2C%22st%22%3A%2259%3A3%3Abbc%2C16%3Af343579f103b7116%2C10%3A1611315201%2C16%3A360adcabd84812cf%2Cc1c668aab33e5327311ff2c3a0cb356918a99d0d6cb65a0da11008340199a802%22%2C%22cdl%22%3Anull%2C%22cid%22%3A%22717762328687-iludtf96g1hinl76e4lc1b9a82g457nn.apps.googleusercontent.com%22%2C%22k%22%3A%22Google%22%2C%22ses%22%3A%225b28397546b247c7994c2d3cd480cc31%22%7D&response_type=code&flowName=GeneralOAuthFlow");
    driver.find_element_by_id("identifierId")\ #entering username
    .send_keys("email@gmail.com")
    sleep(2)
    driver.find_element_by_id("identifierNext").click() #clicking next
    driver.find_element_by_name("password")\ #entering password
    .send_keys("password")
    driver.find_element_by_id("passwordNext").click()#clicking next
    sleep(2)
    driver.get("https://mail.google.com/mail/u/0/#inbox") #going to email inbox
    
Insula
  • 999
  • 4
  • 10
-1

Click Insert → Link or press Ctrl + K (Cmd + K in Mac). You can also click the Insert link button on the toolbar.and your connection problem or email id you can please refresh and restart.