Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    TOTP generated using pyotp is not validating in SmartAPI login (Invalid totp AB1050)

    Python SDK
    3
    7
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      P187170 last edited by

      Hello SmartAPI Team,

      I am trying to authenticate using the SmartAPI Python SDK with TOTP enabled.

      However, the login request consistently returns the following error:

      Error Code: AB1050
      Message: Invalid totp

      Details of my setup:

      • Python version: 3.13
      • Library: smartapi-python
      • TOTP generated using: pyotp
      • Authentication method: client_id + password + totp

      My login code:


      from SmartApi import SmartConnect
      import pyotp

      api_key = "API_KEY"
      client_id = "CLIENT_ID"
      password = "PASSWORD"
      totp_secret = "SECRET_KEY"

      totp = pyotp.TOTP(totp_secret).now()

      obj = SmartConnect(api_key)

      data = obj.generateSession(client_id, password, totp)

      print(data)

      Troubleshooting steps already performed:

      1. Verified that TOTP generated using pyotp matches the TOTP generated using online generator:
        https://totp.danhersam.com

      2. Verified that the same secret key produces identical OTP in multiple generators.

      3. System time synchronized with internet time server.

      Despite this, SmartAPI login still returns:

      {
      "status": False,
      "message": "Invalid totp",
      "errorcode": "AB1050"
      }

      Could you please clarify:

      1. Is there a specific method required to generate TOTP for SmartAPI?
      2. Does SmartAPI require TOTP generated from the SmartAPI TOTP enable page specifically?
      3. Are there any restrictions on authenticator apps (Google Authenticator / Microsoft Authenticator)?

      Any guidance would be greatly appreciated.

      Thank you.

      A J 2 Replies Last reply Reply Quote 0
      • A
        algo_trading_50 @P187170 last edited by

        @p187170 Pass (4 digits) MPIN as string in the password field.

        password = "MPIN"
        
        1 Reply Last reply Reply Quote 0
        • J
          jaideep_bahadur @P187170 last edited by

          Hi @p187170 and Smart API team, is static IP mandatory for algo trading ? i believe IP6 address keeps on changing, what IP has to be mentioned while creating an app if it is mandatory ? Please guide. Thanks

          A 1 Reply Last reply Reply Quote 0
          • A
            algo_trading_50 @jaideep_bahadur last edited by

            @jaideep_bahadur Yes, static IP is mandatory. Changing IPv6, means you are most probably be using mobile data. For static IP, either broadband service with static IP so you can run algo from your system or else VPS service that also provide static IP.

            J 1 Reply Last reply Reply Quote 0
            • J
              jaideep_bahadur @algo_trading_50 last edited by

              @algo_trading_50 thanks for the reply. i am connected through wifi only but observed daily IPv6 address keep on changing. Getting a dedicated IP is possible if i ask customer care of internet provider ?

              A 1 Reply Last reply Reply Quote 0
              • A
                algo_trading_50 @jaideep_bahadur last edited by

                @jaideep_bahadur Yes, read here.

                J 1 Reply Last reply Reply Quote 0
                • J
                  jaideep_bahadur @algo_trading_50 last edited by

                  @algo_trading_50 Thanks a lot for your quick and precise help :)

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post