You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/develop/msal-error-handling-python.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,34 @@ In MSAL for Python, most errors are conveyed as a return value from the API call
25
25
* A successful response contains the `"access_token"` key. The format of the response is defined by the OAuth2 protocol. For more information, see [5.1 Successful Response](https://tools.ietf.org/html/rfc6749#section-5.1)
26
26
* An error response contains `"error"` and usually `"error_description"`. The format of the response is defined by the OAuth2 protocol. For more information, see [5.2 Error Response](https://tools.ietf.org/html/rfc6749#section-5.2)
27
27
28
-
When an error is returned, the `"error_description"` key contains a human-readable message; which in turn typically contains a Microsoft identity platform error code. For details about the various error codes, see [Authentication and authorization error codes](./reference-aadsts-error-codes.md).
28
+
When an error is returned, the `"error_description"` key contains a human-readable message; which in turn typically contains a Microsoft identity platform error code. If the `"error code"`, for example, is `"interaction_required"`, you may prompt the user to provide additional information to complete the authentication process. If the `"error code"` is `"invalid_grant"`, you may prompt the user to reenter their credentials. The following snippet is an example of error handling in MSAL for Python.
29
29
30
-
In MSAL for Python, exceptions are rare because most errors are handled by returning an error value. The `ValueError` exception is only thrown when there is an issue with how you are attempting to use the library, such as when API parameter(s) are malformed.
result = app.acquire_token_silent(scopes=scopes, account=None)
42
+
43
+
ifnot result:
44
+
result = app.acquire_token_silent(scopes=scopes)
45
+
46
+
if"access_token"in result:
47
+
print("Access token: %s"% result["access_token"])
48
+
else:
49
+
print("Error code: %s"% result.get("error_code"))
50
+
51
+
```
52
+
53
+
For more information about the various error codes, see [Authentication and authorization error codes](./reference-aadsts-error-codes.md).
54
+
55
+
In MSAL for Python, exceptions are rare because most errors are handled by returning an error value. The `ValueError` exception is only thrown when there's an issue with how you're attempting to use the library, such as when API parameter(s) are malformed.
0 commit comments