Help Center> Optical Character Recognition> FAQ> API> Why Is Status Code 401 Returned After a Token Is Obtained?

Why Is Status Code 401 Returned After a Token Is Obtained?

If status code 401 is returned when OCR is called in token mode, the token has expired. The validity period of a token is 24 hours. You are advised to set a timely update mechanism.

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 the Python programming language to obtain a token again when the existing one is expired, see the HWOcrClientToken.py code in the SDK(Python) file, as shown in the following figure.