Fyers API error - Could not authenticate the user

This is the simple code that I have written based on fyers api docs

import base64

from datetime import datetime

import json

import os

 

import boto3

from botocore.exceptions import ClientError

 

from fyers_api import fyersModel

from fyers_api import accessToken

 

REDIRECT_URL = 'https://www.google.co.in/'

SECRET_NAME = "fyers_app_secret"

REGION_NAME = "ap-northeast-1"

ACCESS_TOKEN_DDB_TABLE_NAME = 'fyersappddbtoken'

 

def get_secret(secret_name, region_name):

   session = boto3.session.Session()

   client = session.client(

       service_name='secretsmanager',

       region_name=region_name

   )

   try:

       get_secret_value_response = client.get_secret_value(

           SecretId=secret_name

       )

       print(get_secret_value_response)

   except ClientError as e:

       raise e

   else:

       if 'SecretString' in get_secret_value_response:

           return get_secret_value_response['SecretString']

       else:

           return base64.b64decode(get_secret_value_response['SecretBinary'])

 

def get_access_token(app_id, app_secret, redirect_url):

   now = datetime.now().strftime("%d%m%Y")

   ddb_client = boto3.client('dynamodb')

   try:

       ddb_response = ddb_client.get_item(

           TableName=ACCESS_TOKEN_DDB_TABLE_NAME,

           Key={

               'date':{'S': now}

           })

       access_token = ddb_response['Item']['access_token']['S']

   except ddb_client.exceptions.ResourceNotFoundException as e:

       raise e

   except KeyError as e:

       session=accessToken.SessionModel(client_id=app_id,

       secret_key=app_secret,redirect_uri=redirect_url,

       response_type='code', grant_type='authorization_code')

       response = session.generate_authcode()

       print("Login URL: ", response)

       auth_code = input("Enter auth code: ")

       session.set_token(auth_code)

       response = session.generate_token()

       access_token = response["access_token"]

       _response = ddb_client.put_item(

           TableName=ACCESS_TOKEN_DDB_TABLE_NAME,

           Item={

               'date': {'S': now},

               'access_token': {'S': access_token}

           })

   return access_token

 

def login():

   app_secret_value = json.loads(get_secret(SECRET_NAME, REGION_NAME))

   app_id = app_secret_value['app_id']

   app_secret = app_secret_value['app_secret']

   access_token = get_access_token(app_id, app_secret, REDIRECT_URL), app_id, app_id

   fyers = fyersModel.FyersModel(client_id=app_id, token=access_token, log_path=os.path.abspath("./logs"))

   print(fyers)

   return fyers

 

if __name__ == "__main__":

   fyers = login()

   print(fyers.get_profile())

 

However I am getting the following error while trying to execute fyers.get_profile()

{'s': 'error', 'code': -17, 'message': 'Could not authenticate the user'}

I am able to successfully get the auth code and access token but getting the above error while trying to get my profile.

Please note that I have already granted the permissions to my app, but still getting this error.

Could you please help me in resolving this? Thanks!

13 replies