Area: API Issues
Sub-Area: Authentication and Authorization
Applies to: OSS + Cloud
Issue
API calls from the DataHub Python SDK fail with 401 (Unauthorized) or 403 (Forbidden) errors, even though you are using an access token. In some cases the same code works at one time and fails at another.
Error Messages
What you see depends on which SDK call you use.
- The REST emitter (
DatahubRestEmitter) raisesOperationalError. When GMS returns a JSON error body, the message isUnable to emit metadata to DataHub GMS: <server message>. When the body is not JSON, the message isUnable to emit metadata to DataHub GMSand the details are in theinfodict undermessage. That text may contain the underlying HTTP error. -
test_connection()raisesUnable to connect to <gms>/config - got an authentication error: <body>.on a 401. -
DataHubGraph.exists()callsraise_for_status(), so an HTTP error other than 404 reaches your code as an exception.
You Might Be Asking
- Why do some of my API calls fail with 401 or 403 errors?
- Why do my calls work sometimes and fail at other times?
- How do I find out which token and which user a failing call uses?
- Do access tokens have scopes or permission levels?
Cause
A protected GMS path returns HTTP 401 with "Unauthorized to perform this action." when the request is not authenticated. A token can fail validation for these reasons:
- The token has expired ("Failed to validate DataHub token. Token has expired.").
- The token has been revoked ("Failed to validate DataHub token: Token has been revoked").
Access tokens have no scope or permission level. The token creation input has only type, actorUrn, duration, durationIso, name and description. To compare what different permission levels can do, use tokens issued for different users or service accounts.
An expired or revoked token fails every call. If calls fail only some of the time, look at these responses:
- When authentication is temporarily unavailable, a protected path returns HTTP 503 with a
Retry-Afterheader and "Authentication is temporarily unavailable. Please retry the request." - A request denied by the GMS rate limiter gets HTTP 429 with
{"error": "Rate limit exceeded"}. This is not a 401 or 403.
Solution
-
Upgrade the SDK. Install the latest release from PyPI:
pip install --upgrade acryl-datahubThe DataHub Cloud v2.4.4 release notes recommend CLI/SDK 1.7.0.19 or later.
-
Test the connection and the token. For DataHub Cloud, the endpoint is
https://<your-instance>.acryl.io/gms.test_connection()fetches<gms>/configand raises on failure. On a 401 the message says "got an authentication error". If you point it at the frontend instead of GMS, the message tells you so.from datahub.emitter.rest_emitter import DatahubRestEmitter emitter = DatahubRestEmitter( "https://<your-instance>.acryl.io/gms", token="<your-token>", ) emitter.test_connection()See Python REST emitter.
-
Check the token.
-
Confirm the token has not expired or been revoked. See Personal Access Tokens.
-
To find which user or service account a token belongs to, call the GraphQL query
getAccessTokenMetadata(token: String!). See Token management. -
To see the platform privileges of the user a token authenticates as, run this GraphQL query with that token:
{ me { platformPrivileges { generatePersonalAccessTokens manageTokens } } }The GraphQL endpoint and the
Authorization: Bearerheader are described in Set up GraphQL. -
For automated jobs, consider a service account. See Service accounts.
-
-
Log the full error in your code.
exists()returnsFalseon a 404 and raises for other HTTP errors, so a 401 or 403 reaches yourexceptblock.import logging from datahub.ingestion.graph.client import DataHubGraph from datahub.ingestion.graph.config import DatahubClientConfig logger = logging.getLogger(__name__) client = DataHubGraph(DatahubClientConfig( server="https://<your-instance>.acryl.io/gms", token="<your-token>", )) urn = "urn:li:dataset:(urn:li:dataPlatform:snowflake,test_db.test_schema.my_table,PROD)" try: if client.exists(urn): print("Entity exists") else: logger.warning("Entity %s does not exist", urn) except Exception as e: logger.error("API call failed: %s", e) raise -
Check for 429 and 503 responses. The REST emitter retries status codes 429, 500, 502, 503 and 504 by default, with up to 4 retries (
retry_max_times).DatahubClientConfigacceptsretry_status_codesandretry_max_timestoo. In self-hosted DataHub, GMS rate limiting is off by default in the application (RATE_LIMITS_ENABLED=false). Self-hosted operators can set theRATE_LIMITS_*variables. See GMS rate limiting. Cloud customers who see 429 responses should contact DataHub Support. -
If errors continue, contact DataHub Support with:
- The timestamps of the errors
- The complete error messages and stack traces
- Sample URNs that fail
- The user or service account the token was issued for (from
getAccessTokenMetadata) and the token's name
Related Documentation
- DataHub APIs Overview
- GraphQL token management
- Set up GraphQL
- Personal Access Tokens
- Python REST emitter
Tags: api, authentication, 401, 403, python-sdk, token, permissions, troubleshooting, client