jugaad-trader icon indicating copy to clipboard operation
jugaad-trader copied to clipboard

issue in asyncio

Open Kanchangk opened this issue 3 years ago • 1 comments

` 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?

Kanchangk avatar Feb 25 '22 15:02 Kanchangk

were you able to resolve the issue?

ssheikh098 avatar Mar 22 '22 02:03 ssheikh098

@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.

sevakram avatar Nov 19 '23 12:11 sevakram