I'm trying to use AWS to automate some procedures, and need to authenticate myself with the API I'm using. The issue is, its way too slow. I'm using a selenium headless chrome browser to connect to the page, fill in the information I need and submit the form (according to other sources I found the TD Ameritrade API only accepts the browser route so there is no way to do it just with requests, if you know otherwise that would be great too). Finding the element on the page takes about 20 seconds, sending the keys maybe a full minute, and trying to submit the form it times out after 5 minutes. Is this an issue with my implementation of selenium, or is it something to do with AWS or the API I'm connecting to? My code is as shown below and the error:
oauth = OAuth2Session(client_code, redirect_uri=redirect)
authorization_url, state = oauth.authorization_url('https://auth.tdameritrade.com/auth')
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
#chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--window-size=1280x1696')
chrome_options.add_argument('--user-data-dir=tmp/user-data')
chrome_options.add_argument('--hide-scrollbars')
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--log-level=0')
chrome_options.add_argument('--v=99')
chrome_options.add_argument('--single-process')
chrome_options.add_argument('--data-path=tmp/data-path')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--homedir=tmp')
chrome_options.add_argument('--disk-cache-dir=tmp/cache-dir')
chrome_options.add_argument('--no-proxy-server')
chrome_options.add_argument("--proxy-server='direct://'");
chrome_options.add_argument("--proxy-bypass-list=*");
chrome_options.add_argument('user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36')
chrome_options.binary_location = "/usr/bin/chromium-browser"
with webdriver.Chrome(options=chrome_options) as driver:
driver.get(authorization_url)
usernamebox = driver.find_element_by_id("username0")
print("found")
usernamebox.send_keys(username)
print("sent")
passbox = driver.find_element_by_id("password")
print("found2")
passbox.send_keys(password)
print("sent2")
passbox.submit()
print("submitted")
Error:
Traceback (most recent call last):
File "/home/ubuntu/environment/td_ameritrade_test.py", line 229, in <module>
td = TDClient()
File "/home/ubuntu/environment/td_ameritrade_test.py", line 172, in __init__
self.oauth_client = self.authenticate_user()
File "/home/ubuntu/environment/td_ameritrade_test.py", line 90, in authenticate_user
passbox.submit()
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 86, in submit
self._parent.execute_script(
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 634, in execute_script
return self.execute(command, {
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 300.000
(Session info: headless chrome=86.0.4240.75)
Any help would be appreciated greatly!