I am using python for generating the access token. I go threw the module and copy the codes. When i run the code, i get the error “{‘s’: ‘error’, ‘code’: -371, ‘message’: ‘Please provide sha256 hash of appId and app secret’}”. I have already generated the 256 hash but did not find any parameter where i can put it. If any body knows kindly help me, i have search everywhere, but did not get any answer.
My code:
session=accessToken.SessionModel(redirect_uri=redirect_uri,
client_id=client_id,
secret_key=secret_key,
response_type='code',
grant_type=grant_type)
Authenticate with the API
auth_code = session.generate_authcode()
print(auth_code)
auth_code = “” #I have put auth code here.
session.set_token(auth_code)
response = session.generate_token()
print(response)
The response i get:
{‘s’: ‘error’, ‘code’: -371, ‘message’: ‘Please provide sha256 hash of appId and app secret’}
Did you find a fix for this? Their documentation is so poor, it doesn’t even show where to pass it as a parameter.
@100547682965380962827
where to pass it as a parameter
If you are using Python SDK, you do NOT need to explicitly provide appIdHash to obtain access token. It will internally calculate it based on the ClientAppId & SecretKey you provide to the Fyers Session Model object, and it will pass it to the Fyers Auth Server for validation.
Check ClientAppId and SecretKey if you are getting this error.
If you are using direct REST API call to obtain Access Token, then you need to explicitly calculate SHA256 of **ClientAppId:SecretKey **and provide it to the appIdHash param in the POST request, along with the auth code.
Refer - FYERS API v3 Docs
checked in the link you shared same error … will you pls share sample code which working …
@madan_kumar_b
If you are getting error with SHA256 using Python SDK, means*** ClientApp_Id and/or Secret_Key ***you entered are incorrect.
This is working.
# Import the required module from the fyers_apiv3 package
from fyers_apiv3 import fyersModel
# Define your Fyers API credentials
client_id = "" # Replace with your client ID
secret_key = "" # Replace with your secret key
redirect_uri = "" # Replace with your redirect URI
response_type = "code"
grant_type = "authorization_code"
# The authorization code received from Fyers after the user grants access
auth_code = ""
# Create a session object to handle the Fyers API authentication and token generation
session = fyersModel.SessionModel(
client_id=client_id,
secret_key=secret_key,
redirect_uri=redirect_uri,
response_type=response_type,
grant_type=grant_type
)
# Set the authorization code in the session object
session.set_token(auth_code)
# Generate the access token using the authorization code
response = session.generate_token()
# Print the response, which should contain the access token and other details
print(response)
You are right, when AppID and/or Secret are Wrong, it wont work. Hash neednt be passed as a parameter when using python SDK