Skip to main content
Question
FYERS API
Lohitha
Lohitha
Asked a question last year

Hashing Error: Please provide sha256 hash of appId and app secret Can someone suggest me am i correctly generating sha 256? from hashlib import sha256 import http.client import json api_id = 'QXXXY5PTC3-100' app_secret = '2MXXX7J1I4' appId_secret = api_id+app_secret h = sha256(appId_secret.encode("utf-8")) appIdHash = h.hexdigest() conn = http.client.HTTPSConnection("api.fyers.in") payload = json.dumps({ "grant_type": "authorization_code", "appIdHash": appIdHash, "code": auth_code }) headers = { 'Content-Type': 'application/json' } conn.request("POST", "/api/v2/validate-authcode", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) {"s": "error", "code": -371, "message": "Please provide sha256 hash of appId and app secret"}

Join FYERS Community to pick others' brains on Trading/Investing

Hi Lohitha,
I would suggest to use this site - https://emn178.github.io/online-tools/sha256.html172
enter the app_id:access_token in the input and check if it matches with the one you are generating.

Edit: Do check the given python script, comment/uncomment the function calls as needed,
 

from fyers_api import fyersModel
from fyers_api import accessToken
import webbrowser


def generate_auth_code(client_id, secret_key, redirect_uri, response_type):
	session = accessToken.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type=response_type)
	auth_code_url = session.generate_authcode()
	webbrowser.open31(auth_code_url,new=1)


def generate_access_token(auth_code, client_id, secret_key, redirect_uri, response_type, grant_type):
	session = accessToken.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type=response_type, grant_type=grant_type)
	session.set_token(auth_code)
	response = session.generate_token()
	access_token = response["access_token"]
	print(access_token)

def data_api_call(client_id, access_token):
	fyers = fyersModel.FyersModel(token=access_token,is_async=False, log_path="/home/user/fyers/fyers-api/logs",client_id=client_id) # Enter you desired log path store the logs on your system
	
	print(fyers.get_profile())
	print()

	history_data = {"symbol":"NSE:SBIN-EQ","resolution":"D","date_format":"0","range_from":"1622097600","range_to":"1622097685","cont_flag":"1"}
	print(fyers.history(history_data))
	print()

	quotes_data = {"symbols": "NSE:SBIN-EQ"}
	print(fyers.quotes(quotes_data))


def main():	
	# enter your client ID (i.e., the app ID)
	client_id = ""

	# Enter the secret key of your app 
	secret_key = ""

	redirect_uri = "https://trade.fyers.in/api-login/redirect-uri/index.html44"
	response_type = "code"

	generate_auth_code(client_id, secret_key, redirect_uri, response_type)

	auth_code = ""
	grant_type = "authorization_code"
	generate_access_token(auth_code, client_id, secret_key, redirect_uri, response_type, grant_type)

	access_token = ""
	data_api_call(client_id, access_token)



if __name__ == '__main__':
	main()