import requests,time,urllib.parse TOK=open('/home/box/.secrets/upstox_access_token').read().strip() H={'User-Agent':'Mozilla/5.0','Accept':'application/json','Authorization':'Bearer '+TOK} def get(path,params=None,auth=True,tries=4): for i in range(tries): try: r=requests.get('https://api.upstox.com'+path,headers=H if auth else {k:v for k,v in H.items() if k!='Authorization'},params=params,timeout=30) if r.status_code==429: time.sleep(2+i*3); continue return r.status_code,(r.json() if r.headers.get('content-type','').startswith('application/json') else r.text[:300]) except Exception as e: err=str(e); time.sleep(2) return -1,err q=urllib.parse.quote