Demandbase Python SDK Common Errors, Troubleshooting, and FAQs

Learn how the Demandbase Python SDK reports errors, retries supported failures, handles rate limits and authentication issues, and provides diagnostic information for troubleshooting.


Understand Demandbase Python SDK Error Types

The primary SDK error type is demandbase.DemandBaseAPIError. The SDK raises DemandBaseAPIError when:

  • The Demandbase API returns an HTTP error response.
  • The SDK prevents a request because required request values are missing.
  • A response has an unexpected shape for the requested SDK method.

Network-level errors, including DNS failures, connection failures, and request timeouts, can be raised by the underlying HTTP client. Catch these errors separately if your application requires custom network retry or alerting behavior.

Handle Errors with the Demandbase Python SDK

Catch DemandBaseAPIError when an API request fails. Catch network, timeout, or unexpected application errors separately when your application requires different handling.

Example: Handle an SDK API Error
import demandbase

try:
    with demandbase.DBClient(timeout=60.0, retry_count=2) as client:
        response = client.b2b_api.list_subscriptions(page=1, per_page=10)
        print(response.model_dump())
except demandbase.DemandBaseAPIError as error:
    print(f"Demandbase API error: {error.http_status_code} - {error.error_message}")
except Exception:
    # Handle network errors, timeouts, or unexpected application errors here.
    raise

Inspect DemandBaseAPIError Details

Use the attributes on DemandBaseAPIError to inspect the failed request and API response.

List of Attributes
AttributeTypeDescription
request_pathstrAPI path associated with the failed request.
http_status_codeintHTTP status code returned by the API or generated by the SDK.
error_messagestrError message returned by the API or generated by the SDK.
request_headersmapping or NoneRequest headers, when available.
response_headersmapping or NoneResponse headers, when available. Useful for rate-limit handling.
payloadobject or NoneRequest payload, when available.
parametersobject or NoneQuery parameters, when available.
Example: Inspect SDK Error Details
except demandbase.DemandBaseAPIError as error:
    print(error.request_path)
    print(error.http_status_code)
    print(error.error_message)
    print(error.response_headers)

Configure Automatic Retries in the Demandbase Python SDK

Use the retry_count argument on DBClient to configure retries for supported failures.

Failures the SDK Automatically Retries
FailureSDK behavior
401 invalid or expired access tokenClears the cached token, requests a new token, and retries the request.
429 rate-limit responseRetries up to retry_count.
500, 502, 503, 504 server errorsRetries up to retry_count.

For 429 and supported 5xx responses, retry backoff starts at 30 seconds and doubles to a maximum of 600 seconds. If all retries are exhausted, the SDK raises DemandBaseAPIError.

Example: Configure Retries
import demandbase 

with demandbase.DBClient(retry_count=2) as client: response = client.b2b_api.list_subscriptions()

Handle Demandbase API Rate Limits

If a 429 rate-limit response remains after configured retries are exhausted, catch DemandBaseAPIError and inspect http_status_code, response_headers, and error_message.

Rate-limit header names can vary by API response. Use the returned headers to decide whether your application should retry later, queue the request, or reduce request volume.

Example: Handle a 429 Rate-Limit Response
except demandbase.DemandBaseAPIError as error:
    if error.http_status_code == 429:
        print("Rate limit reached. Retry later.")
        print(error.response_headers)
    else:
        raise

Demandbase Python SDK Authentication Errors

The SDK reads credentials from the DEMANDBASE_CLIENT_ID and DEMANDBASE_CLIENT_SECRET environment variables. If either value is missing, client initialization raises RuntimeError.

If credentials are invalid or do not provide access to the requested API, the SDK raises DemandBaseAPIError.

Authentication Error Checklist
  • Confirm DEMANDBASE_CLIENT_ID and DEMANDBASE_CLIENT_SECRET are set in the runtime environment.
  • Confirm the client ID and client secret are valid.
  • Confirm the API Key Set includes the API permissions required by your integration.
  • Confirm your integration is calling the production Demandbase API.

Demandbase Python SDK Validation and Exceptions

The SDK validates some inputs before sending requests. Depending on the validation failure, the SDK can raise ValueError, TypeError, or DemandBaseAPIError.

List of Exceptions
ScenarioException
Page number is less than 1ValueError
Results-per-page value is less than 1ValueError
Local CSV file path cannot be readValueError
CSV input is not a pandas.DataFrame, bytes, or path stringValueError or TypeError, depending on the method
Demandbase API error responseDemandBaseAPIError
Required export job fields are missingDemandBaseAPIError
Example: Handle an Invalid Request Value
try:
    with demandbase.DBClient() as client:
        client.b2b_api.list_subscriptions(page=0)
except ValueError as error:
    print(f"Invalid request value: {error}")

Protect Sensitive Data in Demandbase Python SDK Logs

SDK logs redact bearer access tokens from authorization headers. Request payloads and query parameters can still contain sensitive business data. Avoid logging full error context in production unless appropriate access controls and retention policies are in place.

Enable SDK logs for troubleshooting
import demandbase

demandbase.enable_logging("INFO")

Use DEBUG only during focused troubleshooting because it can produce verbose request diagnostics.


Troubleshoot Common Demandbase Python SDK Issues

List of Common Issues
IssueWhat to check
Missing credential errorConfirm DEMANDBASE_CLIENT_ID and DEMANDBASE_CLIENT_SECRET are set before creating DBClient.
401 persists after retryConfirm the credentials are valid and have not been rotated or revoked.
403 or permission-related errorsConfirm the API Key Set has permission for the endpoint or data type being requested.
429 responsesReduce request volume, increase spacing between requests, or retry later based on response headers.
Timeout errorsConfirm outbound network access and increase the timeout, in seconds, for requests that normally take longer.
Unexpected response dataConfirm request filters, entity type, and account permissions match the data you expect to receive. If the issue persists, capture the request context and error details for Demandbase Support.

Demandbase Python SDK FAQs

List of FAQs
QuestionAnswer
How do I get API credentials?

A Demandbase administrator can create an API Key Set in Demandbase One and generate a token that provides a client ID and client secret. During setup, select the API permissions your integration needs. If the required API options are not available, contact your Demandbase account team.

See Generate and Manage API Key Sets.

Is there a sandbox or staging environment for SDK testing?No. The SDK connects to the production Demandbase API. Use test records, small request sizes, and non-destructive read operations when validating a new integration.
Does the SDK make synchronous requests?Yes. SDK methods wait for the API response before returning or raising an error.
How do I install the latest SDK version?Run pip install demandbase-sdk. Use a pinned version only when your deployment process requires reproducible installs.
Does the SDK handle token refresh?Yes. The SDK manages access tokens and retries a request when a token is invalid or expired.
Where can I find the full list of available methods and models?See Demandbase SDK Reference.

Did this page help you?