Errors and troubleshooting
Handle API errors
from Analog_WakaTime_SDK.exceptions import ApiException
try:
profile = await profile_api.main_api_v1_get_my_profile_info_get()
except ApiException as error:
if error.status == 401:
print("The token is missing, invalid, disabled, or expired")
elif error.status == 403:
print("The account or subscription does not allow this operation")
elif error.status == 429:
print("Rate limit reached; retry after the response window")
else:
print(error.status, error.body or error.reason)
Common statuses
| Status | Meaning | Action |
|---|---|---|
400 | invalid request model or field value | correct the request before retrying |
401 | missing, invalid, disabled, or expired token | verify or rotate the token |
403 | account or subscription does not allow the request | use an allowed history period or upgrade access |
404 | resource or token UUID does not exist | verify the identifier |
409 | operation conflicts with current state | inspect the response body |
429 | gateway rate limit reached | retry after the rate-limit window |
5xx | temporary gateway or service failure | retry with exponential backoff |
Access HTTP metadata
Use the _with_http_info variant of a generated operation:
response = await profile_api.main_api_v1_get_my_profile_info_get_with_http_info()
print(response.status_code)
print(response.headers)
print(response.data.to_dict())
Set timeouts
profile = await profile_api.main_api_v1_get_my_profile_info_get(
_request_timeout=(5, 30),
)
Use a single number for a total timeout or a tuple for connection and read timeouts.
The SDK requests localhost
The installed package was generated from an older OpenAPI document. Reinstall the latest SDK with --force-reinstall --no-cache-dir. A current production package reads the server URL embedded during generation.
A documented method is missing
The documentation and package must come from the same release. Force-reinstall the newest SDK if Python raises AttributeError for a documented operation.
403 subscription-required
Free accounts can request no more than the latest seven days. Use period="week" where the SDK operation exposes a history-period argument.
Logging safety
- never log
Configuration.access_token - never include an API token in an exception message
- response bodies can contain private profile and activity data
- redact authorization headers in HTTP debug logging