Request for access token is throwing errors when being done for multiple accounts

healthsecure15
Hi,

I have a few accounts all subscribed to API. Since the introduction of TOTP I am getting random errors which do not show up when I try to recreate the issue.

Here is the code I am using:

secret = sec
key = k
kite = KiteConnect(ky)
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
url = 'https://kite.trade/connect/login?api_key={}'.format(key)
driver.get(url)
# manual input of password
# manual input of id
input('Press Enter')
driver.find_element_by_xpath("*//button[@type='submit']").click()
# manual input of TOTP
print('Current URL\n', driver.current_url)
if 'request_token=' in driver.current_url:
pass
else:
print('\n\n\n\n\n{}'.format(driver.page_source))
print('\n\n\n\n\n\n\n\n\nThere is an error on page')
tkn = (driver.current_url).split('request_token=')[1]
tkn = tkn.split('&')[0]
driver.quit()
user = kite.generate_session(tkn, secret)
kite.set_access_token(user["access_token"])
access_tkn = user['access_token']
loc_tkn = '/home/xxxxxx/tkn'
os.chdir(loc_tkn)
print(access_tkn, file=open('access_tkn.txt', 'w'))


The error log when I do this at 8:30 AM, occurs on the third account:

Current URL:
https://kite.zerodha.com/#loggedout
Traceback (most recent call last):
File "/home/request_token.py", line 16, in
get_request_token()
File "/home/login.py", line 147, in get_request_token
tkn = (driver.current_url).split('request_token=')[1]

I have set a delay of 8 seconds between the token requests.

When I run the same process after 9:30AM I encounter no problem at all. Any suggestion on how to avoid this particular error, time recommendation, chrome to private mode or similar?

Thanks
Sign In or Register to comment.