Navigate to the app details screen and check if you have entered the correct client id. Ensure there are no spaces at the beginning or end of the client id. You must use the Kite Connect APIs with the same client ID that you used to create the app.
I am using the code as below. I can go to the step where i enter my kite web password but on entering the mobile code it just return back asking to return the mobile code agaain and again . It does go further to generate the token code url . Its the same behaviour whether using paid or personal api.
import sys import os
# Add workspace to path workspace_root = os.path.abspath(os.path.dirname(__file__)) if workspace_root not in sys.path: sys.path.insert(0, workspace_root)
from kiteconnect import KiteConnect
# Step 1: Initialize KiteConnect with your API key api_key = "x9izwrddgkgup42l" api_secret = "******************" # Use actual credentials or update with your secret
kite = KiteConnect(api_key=api_key)
# Step 2: Generate the login URL print("Login URL:", kite.login_url()) print("\n⚠️ Note: To use this script with real data:") print("1. Open the login URL above in your browser") print("2. Log in and authorize the app") print("3. Extract the 'request_token' from the redirect URL") print("4. Replace it in the code below\n")
# Step 3: Exchange request_token for access_token # For demonstration, use a mock token (will fail with real API) request_token = "mock_request_token" print(f"Using demo request token: {request_token}")
try: data = kite.generate_session(request_token, api_secret=api_secret) kite.set_access_token(data["access_token"]) print("Access token generated successfully:", data["access_token"]) except Exception as e: print(f"Expected error with demo token: {e}") print("\n✓ Code is ready to use with real credentials!")
You may refer to the similar discussion here.
import sys
import os
# Add workspace to path
workspace_root = os.path.abspath(os.path.dirname(__file__))
if workspace_root not in sys.path:
sys.path.insert(0, workspace_root)
from kiteconnect import KiteConnect
# Step 1: Initialize KiteConnect with your API key
api_key = "x9izwrddgkgup42l"
api_secret = "******************" # Use actual credentials or update with your secret
kite = KiteConnect(api_key=api_key)
# Step 2: Generate the login URL
print("Login URL:", kite.login_url())
print("\n⚠️ Note: To use this script with real data:")
print("1. Open the login URL above in your browser")
print("2. Log in and authorize the app")
print("3. Extract the 'request_token' from the redirect URL")
print("4. Replace it in the code below\n")
# Step 3: Exchange request_token for access_token
# For demonstration, use a mock token (will fail with real API)
request_token = "mock_request_token"
print(f"Using demo request token: {request_token}")
try:
data = kite.generate_session(request_token, api_secret=api_secret)
kite.set_access_token(data["access_token"])
print("Access token generated successfully:", data["access_token"])
except Exception as e:
print(f"Expected error with demo token: {e}")
print("\n✓ Code is ready to use with real credentials!")