After passing user_id,password,twofa below Exception comes how to set up TwoFA for Python web api {'status': 'error', 'message': 'Invalid TOTP. 3 attempt(s) remain before the account is locked.', 'data': {'attempts_remaining': 3}, 'error_type': 'TwoFAException'}
login_url = "https://kite.zerodha.com/api/login"
r = s.post(login_url, data={"user_id": user_id, "password":password})
j = json.loads(r.text)
print(j)
twofa_url = "https://kite.zerodha.com/api/twofa"
data = {"user_id": user_id, "request_id": j['data']["request_id"], "twofa_value": twofa }
r = s.post(twofa_url, data=data)
j = json.loads(r.text)
Go through this thread.