Arindam Ghosh
 · Algo Trader

Error in API Login

Hi,

I use the standard code to log into Fyers API. From yesterday I am facing error.

BASE_URL = "https://api-t2.fyers.in/vagator/v2"

BASE_URL_2 = "https://api.fyers.in/api/v2"

URL_SEND_LOGIN_OTP = BASE_URL + "/send_login_otp"

URL_VERIFY_TOTP = BASE_URL + "/verify_otp"

URL_VERIFY_PIN = BASE_URL + "/verify_pin"

URL_TOKEN = BASE_URL_2 + "/token"

URL_VALIDATE_AUTH_CODE = BASE_URL_2 + "/validate-authcode"

def send_login_otp(fy_id, app_id):

try:

payload = {

"fy_id": fy_id,

"app_id": app_id

}

result_string = requests.post(url=URL_SEND_LOGIN_OTP, json=payload)

if result_string.status_code != 200:

return [ERROR, result_string.text]

result = json.loads(result_string.text)

request_key = result["request_key"]

return [SUCCESS, request_key]

except Exception as e:

return [ERROR, e]

#####

FY_ID = row['login_id'] # Your fyers ID

APP_ID_TYPE = "2" # Keep default as 2, It denotes web login

TOTP_KEY = row['code'] # TOTP secret is generated when we enable 2Factor TOTP from myaccount portal

PIN = row['yob'] # User pin for fyers account

APP_ID = row['api_key'][:-4] # App ID from myapi dashboard is in the form appId-appType. Example - EGNI8CE27Q-100, In this code EGNI8CE27Q will be APP_ID and 100 will be the APP_TYPE

REDIRECT_URI = row['redirect_uri'] # Redirect url from the app.

APP_TYPE = "100"

APP_ID_HASH = hashlib.sha256((row['api_key']+":"+row['api_secret']).encode()).hexdigest() # SHA-256 hash of appId-appType:appSecret

send_otp_result = send_login_otp(fy_id=FY_ID, app_id=APP_ID_TYPE)

if send_otp_result[0] != SUCCESS:

logging.info(f"send_login_otp failure - {send_otp_result[1]}")

break

########

The output is as follows

2023-11-16 13:04:46,344 - start

2023-11-16 13:04:46,589 - C0 Fyers

2023-11-16 13:04:46,714 - send_login_otp failure - <html>

<head><title>502 Bad Gateway</title></head>

<body>

<center><h1>502 Bad Gateway</h1></center>

<hr><center>cloudflare</center>

</body>

</html>

2023-11-16 13:04:46,714 - end

9 replies