Kotak-Neo / kotak-neo-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to login

ankarne opened this issue · comments

I am unable to login either with access token or consumer key and secret.
My code:
client = neo_api_client.NeoAPI(consumer_key="",consumer_secret="", environment='prod')
or
client = neo_api_client.NeoAPI(access_token='',environment='prod')
client.login(mobilenumber="",password="")

Error with access token:
neo_api_client.exceptions.ApiValueError: View Token hasn't been Generated Kindly Call the Login Function and Try to Generate OTP

print(client.api_client.configuration.dict) before client.login() gives the following
{'consumer_key': None, 'consumer_secret': None, 'host': 'prod', 'base64_token': 'hidden', 'bearer_token': 'hidden', 'view_token': None, 'sid': None, 'userId': None, 'edit_token': None, 'edit_sid': None, 'edit_rid': None, 'serverId': None, 'login_params': None, 'neo_fin_key': None}

Error with consumer key and secret:
{"data": "{"data": {"Code": 401, "Message": "Error occurred to initialise the session"}}"}
TypeError: can only concatenate str (not "NoneType") to str

print(client.api_client.configuration.dict) before client.login() gives the following
{'consumer_key': 'hidden', 'consumer_secret': 'hidden', 'host': 'prod', 'base64_token': 'hidden', 'bearer_token': None, 'view_token': None, 'sid': None, 'userId': None, 'edit_token': None, 'edit_sid': None, 'edit_rid': None, 'serverId': None, 'login_params': None, 'neo_fin_key': None}

How do I get around this?

I am also having the same issue. Were you able to find any solution for this?

URLs given in UAT is not working. Use production, it's working

URLs given in UAT is not working. Use production, it's working

If you see my code, i have mentioned the environment as PROD.
Did you do change anything else to get it to work?

@ankarne

Oh, I see yours is already set to "prod". I haven't changed anything except switching from "uat" to "prod", and it's exactly the same as yours.
client = NeoAPI(consumer_key="", consumer_secret="", environment="prod")

The main issue I discovered while debugging is that the URLs specified in neo_api_client.urls.py and neo_api_client.settings.py for UAT have not been updated, which is causing the error. I suspect that somehow your code is still calling the UAT URLs, which would explain the exact error you mentioned. Also, please verify that the consumer key and secret are configured for production only and not for UAT.

@ananducherakkal
The URLs in the files you have mentioned are the same as in the git files here. I even commented out UAT from the urls files and removed importing UAT from all the files.
I did not find anyway to figure out if consumer key and secret are configured for production or UAT. Have attached the screenshot.

Screenshot_22
Also would like to note that I am not able to create new applications or modify the current one. It just mentions "ERROR"

@ankarne Yes consumer key and secret looks good, its the same which I have used.

To check whether the issue is on the account side, you could directly hit the APIs(given in url.py) from Python or Postman. If there are errors, at least you could receive an error message to help figure out the problem.

For session:

import requests
import base64

auth_token = base64.b64encode(f"{consumer_key}:{consumer_secret}".encode()).decode('utf-8')
response = requests.post("https://napi.kotaksecurities.com/oauth2/token",
                         json={"grant_type": "client_credentials"},
                         headers={"Authorization": f"Basic {auth_token}"})
print(response.text)

For login:

response = requests.post("https://gw-napi.kotaksecurities.com/login/1.0/login/v2/validate",
                         json={"mobileNumber": "", "password": ""},
                         headers={"Authorization": f"Bearer {accessTokenFromSession}"})
print(response.text)

Have you subscribed to the Login APIs?