Python Forum

Full Version: Not able to sign into gmail using selenium
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to automate gmail by downloading attachments from my inbox using selenium. But, it is showing me this error "This browser or app may not be secure". I looked around and found that OAuth will solve the problem. But, I don't know how to use it or if it is the right tool to use. Can anyone help me solve this error. Is Oauth the right tool? Will using any other browser solve the problem?

I am getting the Options() because I am not able to open chrome as it is not in the default location. If you have a solution for that too. Thanks

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "/opt/google/chrome/google-chrome"    
options.add_argument("--start-maximized") 
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") 

options.add_experimental_option("excludeSwitches["enableautomation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, 
executable_path=r'./chromedriver')
driver.get('http://gmail.com/')
Error that is shown by gmail: 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.
Out of interest, why Selenium? Gmail has a REST API, which does seem to have an endpoint for getting attachments.
Just enable less secure apps on Gmail and use their API, but if you really need to use selenium Google blocks bots from what I've experienced.
(Nov-18-2020, 06:31 AM)ndc85430 Wrote: [ -> ]Out of interest, why Selenium? Gmail has a REST API, which does seem to have an endpoint for getting attachments.

I want the attachments as Zip. and I don't know if it has an option for it. But, I will be trying the API. Thanks
(Nov-18-2020, 11:51 AM)Anarab Wrote: [ -> ]Just enable less secure apps on Gmail and use their API, but if you really need to use selenium Google blocks bots from what I've experienced.

I have seen people do it and also found people do it using Oauth here: https://gist.github.com/ikegami-yukino/5...76cb41fe93 . But, surely I will be trying the API and see if there is any problem. And Do I need any authorization for accessing my Gmail? using the API.