It looks like you're new here. If you want to get involved, click one of these buttons!
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 9 10:01:26 2020
@author: Administrator
"""
from kiteconnect import KiteConnect
from selenium import webdriver
import time
import os
cwd = os.chdir("C:/Users/hozef/OneDrive/Desktop/New_Logic")
def autologin():
token_path = "credentials.txt"
key_secret = open(token_path, 'r').read().split()
kite = KiteConnect(api_key=key_secret[0])
service = webdriver.chrome.service.Service('./chromedriver')
service.start()
options = webdriver.ChromeOptions()
# options.add_argument('--headless')
options = options.to_capabilities()
driver = webdriver.Remote(service.service_url, options)
driver.get(kite.login_url())
driver.implicitly_wait(15)
username = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/div/div/div[2]/form/div[1]/input')
password = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/div/div/div[2]/form/div[2]/input')
driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/div/div/div[2]/form/div[4]/button').click()
pin = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/div/div/div[2]/form/div[2]/div/input')
driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/div/div/div[2]/form/div[3]/button').click()
time.sleep(15)
request_token = driver.current_url.split('=')[1].split('&action')[0]
with open('request_token.txt', 'w') as the_file:
the_file.write(request_token)
driver.quit()
autologin()
# generating and storing access token - valid till 6 am the next day
request_token = open("request_token.txt", 'r').read()
key_secret = open("credentials.txt", 'r').read().split()
kite = KiteConnect(api_key=key_secret[0])
data = kite.generate_session(request_token, api_secret=key_secret[1])
with open('access_token.txt', 'w') as file:
file.write(data["access_token"])
TokenException: Token is invalid or has expired.
We have been recommending not to automate login since the day we went live. It is against the regulation, so we recommend you don't automate login.