Smart API Login issue
-
Hello @shreyas2290
Can you please provide which API you are using for the same
Regards,
SmartAPI Team -
@Moderator_3
I am using trading api -
Following is the code. I have entered IP address, public IP address, mac address, client id, pin, API key and totp correctly. Still I am getting error. The following code is from API Documentation. I have pasted the error in the end.
import http.client
import mimetypes
conn = http.client.HTTPSConnection(
"apiconnect.angelbroking.com"
)
payload = "{\n"clientcode":"CLIENT_ID"
,\n"password":"CLIENT_PIN"\n
,\n"totp":"TOTP_CODE"\n}"
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-UserType': 'USER',
'X-SourceID': 'WEB',
'X-ClientLocalIP': 'CLIENT_LOCAL_IP',
'X-ClientPublicIP': 'CLIENT_PUBLIC_IP',
'X-MACAddress': 'MAC_ADDRESS',
'X-PrivateKey': 'API_KEY'
}
conn.request(
"POST", "/rest/auth/angelbroking/user/v1/loginByPassword", payload, headers)res = conn.getresponse()
data = res.read()
print(data.decode("utf-8")){"status":false,"message":"Invalid totp","errorcode":"AB1050","data":null}
-
@Moderator_3 I am not able to enable totp from ui and when i try to generate it using secret key i am getting Error: Invalid totp.
-
Hello @sunil_modi
Can you please use this pyotp library
totp = pyotp.TOTP(token).now()
https://pypi.org/project/pyotp/Regards,
SmartAPI Team -
@Moderator_3 This is what i am doing, still getting same error
secret_key = "f6f7faf4-7986-45-be2f-751f890b9be2"
base32_secret = base64.b32encode(secret_key.encode()).decode()
Generate a TOTP instance
totp = pyotp.TOTP(base32_secret).now()
-
@Moderator_3 i am doing the same still getting this error
secret_key = "f6f7faf4-7986-45-be2f-751f890b9be2"
base32_secret = base64.b32encode(secret_key.encode()).decode()
totp = pyotp.TOTP(base32_secret)
obj = SmartConnect(api_key=api_key)
data = obj.generateSession(client_id, '5437', totp.now())
-
Home @sunil_modi
Can you please don't encode the string which you are getting from the totp screen.Instead of encoding please pass it directly
Regards,
SmartAPI Team -
@Moderator_3 if i directly pass the secret key it is giving error like
-
Hi,
Can you please solve this issue.{"status":false,"message":"Invalid totp","errorcode":"AB1050","data":null}
-
@Moderator_3 i got this error when i don't encode
when i simply pass secret key i got this error
would you please give me connection code
-
Hello @sunil_modi
I can see still you are passing the encoded secret_key while calling the pyotp.please check and confirm the same
Regards,
SmartAPI Team -
@Moderator_3 i am not able to login to totp screen. Everytime i try to login using mpin i am getting this error
-
@sunil_modi are you passing your mobile MPIN in the password field? Please pass that here. We are working to change this nomenclature here.
Also, the secret key for TOTP is not the secret key generated along with the API key in the app. The string which you need to pass in the TOTP is the one generated below the QR code in TOTP Generation.