How can i easily access my access token ?

1krishnagupta
1krishnagupta edited January 14 in Python client
At this time I'm using this code to access the access token -
kite = KiteConnect(api_key=zerodha_api_key)
driver = webdriver.Chrome(Webdriver_chrome)

url = kite.login_url()
driver.get(url)
print("login Url: ", url)


# Login Into Zerodha Account
user_id = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//*[@id='userid']")).send_keys(zerodha_user_id)
password = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//*[@id='password']")).send_keys(zerodha_password)
submit = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//*[@id='container']/div/div/div/form/div[4]/button")).submit()
auth_key = pyotp.TOTP(zerodha_totp_key)
print(auth_key.now())
totp = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//*[@id='totp']")).send_keys(auth_key.now())
submit_btn = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//*[@id='container']/div/div/div/form/div[3]/button")).submit()

# Request Token
sleep(2)
Current_url = driver.current_url
driver.close()
print(Current_url)
initial_token = Current_url.split('request_token=')[1]
request_token = initial_token.split('&')[0]
print("request_token: ", request_token)

# Access Token
data = kite.generate_session(request_token, api_secret=zerodha_api_secrets)
kite.set_access_token(data["access_token"])
acc_tkn = data['access_token']
In this Code I'm using selenium method for login, and then fetching request token and then access token.
But I want to get my access token easily and I don't want to make it lengthy. because in this process I'm fetching request token, and during request token, most of the time, it gives errors, or some time session also fails.
So please help me, how can I solve this issue, and make it easier.
And if someone can provide me a code then, it would be a big help for me, so please can you provide me a code as well?

actually some times I'm getting this error as well-
HTTPSConnectionPool(host='api.kite.trade', port=443): Max retries exceeded with url: /quote/ltp?i=NFO%3ABANKNIFTY22JANFUT (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000029535458B20>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
  • sujith
    It is mandatory by the exchange that a user has to login manually at least once a day. We don't recommend automating login flow.
This discussion has been closed.