Skip to content

Conversation

Ankitkalauni
Copy link

Handles the failure of generateSession.

the request returns success = False on failure, with a message which is logged and returned.

The Failed returned JSON from _postRequest() is handled

Example of requests.request().content returning success = False on failure
{'success': False, 'message': 'Client Is Block For Trading', 'errorCode': 'AB1006', 'data': ''}

please merge this to avoid the below errors

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In [1], [line 27](vscode-notebook-cell:?execution_count=1&line=27)
     [24](vscode-notebook-cell:?execution_count=1&line=24)     raise e
     [26](vscode-notebook-cell:?execution_count=1&line=26) correlation_id = "abcde"
---> [27](vscode-notebook-cell:?execution_count=1&line=27) data = smartApi.generateSession(username, pwd, totp)

File [c:\Users\ankit.ka\AppData\Local\Programs\Python\Python39\lib\site-packages\SmartApi\smartConnect.py:241](file:///C:/Users/ankit.ka/AppData/Local/Programs/Python/Python39/lib/site-packages/SmartApi/smartConnect.py:241), in SmartConnect.generateSession(self, clientCode, password, totp)
    [237](file:///C:/Users/ankit.ka/AppData/Local/Programs/Python/Python39/lib/site-packages/SmartApi/smartConnect.py:237) params={"clientcode":clientCode,"password":password,"totp":totp}
    [238](file:///C:/Users/ankit.ka/AppData/Local/Programs/Python/Python39/lib/site-packages/SmartApi/smartConnect.py:238) loginResultObject=self._postRequest("api.login",params) 
--> [241](file:///C:/Users/ankit.ka/AppData/Local/Programs/Python/Python39/lib/site-packages/SmartApi/smartConnect.py:241) if loginResultObject['status']==True:
    [242](file:///C:/Users/ankit.ka/AppData/Local/Programs/Python/Python39/lib/site-packages/SmartApi/smartConnect.py:242)     jwtToken=loginResultObject['data']['jwtToken']
    [243](file:///C:/Users/ankit.ka/AppData/Local/Programs/Python/Python39/lib/site-packages/SmartApi/smartConnect.py:243)     self.setAccessToken(jwtToken)

KeyError: 'status'

Handles the failure of generateSession.

the request returns success = False on failure, with a message which is logged and returned.
@Ankitkalauni Ankitkalauni changed the title Updated smartConnect.py generateSession() Fixed smartApi.generateSession Error "KeyError: 'status'" Jan 27, 2024
@Ankitkalauni Ankitkalauni changed the title Fixed smartApi.generateSession Error "KeyError: 'status'" Fixed smartApi.generateSession() Error "KeyError: 'status'" Jan 27, 2024
@dmbagul545
Copy link

About vigilant mode

1 similar comment
@dmbagul545
Copy link

About vigilant mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants