Hi @admin
from SmartApi import SmartConnect
import getpass
Ask user input securely
api_key = input("API Key: ").strip()
client_code = input("Client Code: ").strip()
password = getpass.getpass("Password: ")
totp = getpass.getpass("TOTP (6 digits): ").strip()
Create SmartConnect object
obj = SmartConnect(api_key=api_key)
Attempt to generate session
resp = obj.generateSession(client_code, password, totp)
Display full response
print("\nLogin Response:", resp)
Check and print the Bearer token if login is successful
if resp.get("status") and resp.get("data") and "jwtToken" in resp["data"]:
bearer_token = resp["data"]["jwtToken"]
print("\n Your Bearer Token:")
print(f"Authorization: Bearer {bearer_token}")
else:
print("\n Login failed:", resp.get("message"))
I have generated the Bearer token using this code but while using it to get historical data it is showing following error
Candle Data Response:
{'success': False, 'message': 'Invalid Token', 'errorCode': 'AG8001', 'data': ''}
OI Data Response:
{'success': False, 'message': 'Invalid Token', 'errorCode': 'AG8001', 'data': ''}