jugaad-py / jugaad-trader

Unofficial python client for Zerodha
https://marketsetup.in/documentation/jugaad-trader/
156 stars 110 forks source link

issue in asyncio #41

Closed Kanchangk closed 10 months ago

Kanchangk commented 2 years ago

` async def fetch_tfa(session, URL, TWOFA_ROUTE, headers, twofa_payload): """ two factor authentication """ async with session.post(URL + TWOFA_ROUTE, data=twofa_payload) as response: return response.cookies['enctoken']

async def main(ohlc_table_name, symbol_table_name, ifStock): """ Login to Zerodha """ URL = "https://kite.zerodha.com/" LOGIN_ROUTE = "api/login" TWOFA_ROUTE = "api/twofa" USER_ID = config.USER_ID PASSWORD = config.PASSWORD TWOFA_VALUE = config.TWOFA_VALUE headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/5', 'origin': URL, 'referer': URL, } login_payload = { 'user_id': USER_ID, 'password': PASSWORD } sem = asyncio.Semaphore(100) async with aiohttp.ClientSession() as session: json_load = await asyncio.gather(fetch(session, URL, LOGIN_ROUTE, headers, login_payload)) twofa_payload = { 'user-id': USER_ID, 'request_id': json_load[0]["data"]["request_id"], 'twofa_value': TWOFA_VALUE, 'skip_session': '' } resp = await asyncio.gather(fetch_tfa(session, URL, TWOFA_ROUTE, headers, twofa_payload)) enc_token = resp[0].value header_update = {'authorization': "enctoken{}".format(enc_token), 'referer': 'https://kite.zerodha.com/dashboard', 'x-kite-version': '2.9.10', 'sec-fetch-site': 'same-origin', 'sec-fetch-mode': 'cors', 'sec-fetch-dest': 'empty',} session.headers.update(header_update) `

I am getting 403 response in twfa stage. can you point out the possible error?

ssheikh098 commented 2 years ago

were you able to resolve the issue?

sevakram commented 10 months ago

@Kanchangk Closing this issue as this is not related to jugaad-trader but I appreciate the effort you are putting in asyncio

I have done asyncio in another project and here is my two cents - In most cases the effort gone into complexity of asyncio is not worth the performance. We can get similar level of performance with threading.

Do let us know how it went.