Unable to login

I am unable to generate auth_code.

I am using this url to generate the token and auth code.

https://api-t1.fyers.in/api/v3/generate-authcode?client_id=<my_id>&redirect_uri=https%3A%2F%2Fwww.google.co.in%2F&response_type=code&state=None
It was working all this time and suddenly stopped generating auth_code url, it just says success. I checked the documentation there is no change there too. Is there any issue at fyers api end?

"

session = fyersModel.SessionModel(

client_id=client_id,

secret_key=secret_key,

redirect_uri=redirect_uri,

response_type=response_type,

grant_type=grant_type

)

newurl = “https://api-t1.fyers.in/api/v3/generate-authcode?client_id=T***-100&redirect_uri=https%3A%2F%2Fwww.google.co.in%2F&response_type=code&state=None

this is the code i have been using since auto-login was removed.

auth_code = newurl[newurl.index(‘auth_code=’)+10:newurl.index(‘&state’)]print(auth_code)session.set_token(auth_code)response = session.generate_token()print(response)access_token = response[“access_token”]a=open(“access_token.txt”,“w”)a.write(access_token)"

Hey @117375893251546738105 ,

Please check the redirect url which needs to be given ,you can follow the documentation for the same , please get back to us if any further clarification is required :
https://myapi.fyers.in/docsv3#tag/Authentication-and-Login-Flow-User-Apps/paths/~1Authentication%20&%20Login%20Flow%20-%20User%20Apps/patch

Hello Abhishek

I have added that too: FYERS - Born to Trade

Under redirect_uri.

Could you please check again?

Thanks for the prompt response

Yes , all of a sudden from yesterday evening the auto login is not happening before that it used to work fine below is my code check if any issue on your side

redirect_uri = “https://trade.fyers.in/api-login/redirect-uri/index.html

def b64(s):

return base64.b64encode(str(s).encode()).decode()

print(“Generating auth-code link …”)

appSession = fyersModel.SessionModel(

client_id=client_id, redirect_uri=redirect_uri,

response_type="code", state="sample",

secret_key=secret_key, grant_type="authorization_code"

)

print(appSession.generate_authcode())

OTP + PIN flow --------------------------------------------------------------

otp1 = requests.post(

"[https://api-t2.fyers.in/vagator/v2/send_login_otp_v2](https://api-t2.fyers.in/vagator/v2/send_login_otp_v2)",

json={"fy_id": b64(FY_ID), "app_id": "2"}

).json()

if datetime.now().second % 30 > 27:

time.sleep(5)

otp2 = requests.post(

"[https://api-t2.fyers.in/vagator/v2/verify_otp](https://api-t2.fyers.in/vagator/v2/verify_otp)",

json={"request_key": otp1["request_key"], "otp": pyotp.TOTP(TOTP_KEY).now()}

).json()

ses = requests.Session()

pin_res = ses.post(

"[https://api-t2.fyers.in/vagator/v2/verify_pin_v2](https://api-t2.fyers.in/vagator/v2/verify_pin_v2)",

json={"request_key": otp2["request_key"], "identity_type": "pin", "identifier": b64(PIN)}

).json()

ses.headers.update({“authorization”: f"Bearer {pin_res[‘data’][‘access_token’]}"})

token_res = ses.post(

"[https://api-t1.fyers.in/api/v3/token](https://api-t1.fyers.in/api/v3/token)",

json={

    "fyers_id": FY_ID, "app_id": client_id[:-4], "redirect_uri": redirect_uri,

    "appType": "100", "code_challenge": "", "state": "None", "scope": "",

    "nonce": "", "response_type": "code", "create_cookie": True,

}

).json()

auth_code = parse_qs(urlparse(token_res[“Url”]).query)[“auth_code”][0]

session = fyersModel.SessionModel(

client_id=client_id, secret_key=secret_key,

redirect_uri=redirect_uri, response_type="code", grant_type="authorization_code"

)

session.set_token(auth_code)

access_token = session.generate_token()[“access_token”]

print(“FYERS TOKEN:”, access_token)

fyers = fyersModel.FyersModel(client_id=client_id, token=access_token, is_async=False, log_path=os.getcwd())

Hey @117375893251546738105 ,

Could you please DM us your contact details so that we can connect and help with this

Try using this code

#Extract auth_code from URL

auth_code = newurl.split(“auth_code=”)[1].split(“&state”)[0]

print(f"Auth Code: {auth_code}")

Set token and generate access token

session.set_token(auth_code)

response = session.generate_token()

print(f"Token Response: {response}")

Save access token to file

access_token = response.get(“access_token”)

if access_token:

with open("access_token.txt", "w") as file:

    file.write(access_token)

else:

print("Error: Access token not found in response.")

Thanks all.
this got resolved by changing url in api manager