Help Center> Optical Character Recognition> FAQs> Token-based Authentication> Why Does the Token Retrieval Process Return a 401 Status Code?
Updated on 2024-06-21 GMT+08:00

Why Does the Token Retrieval Process Return a 401 Status Code?

There are several reasons.

  1. A token is valid for 24 hours. If you receive a 401 status code when calling the OCR service using a token, it means that the token has expired. To continue using the OCR service, you should obtain a new token.

    The retry mechanism has been configured in the OCR SDK to update the token. If the token is invalid and status code 401 is returned, the OCR SDK sends a request to obtain a token again.

    For details about how to use Python to obtain a token again when the existing one has expired, see the HWOcrClientToken.py code in the SDK(Python) file.

  2. Your IAM username matches the master account name. For security reasons, the token for this account is restricted and cannot be used to ensure the safety of your assets. You are advised to create a new IAM user with a different name and grant it the necessary permissions before proceeding with any related operations. For details, see Creating an IAM User and Assigning Permissions to IAM Users.
  3. You have recently changed your password, subscribed to a new service, or modified your permissions. As a result, your token may have become invalid. You will need to obtain a new token in this case.

Token-based Authentication FAQs

more