Set request timeouts
Give the client a default timeout and override it for one call with RequestOptions.
- Stable unknown
- Release candidate not available
- Development since 0.2.0-dev.36+f12b151
Complexity: 1 of 5 · Client: Python · Time: about 5 minutes
Every request has a timeout. Set the default on the client, then pass RequestOptions to any method that calls the API when one call needs a different limit.
Set the client's timeoutServer-side
Ovok applies its timeout to every request. It defaults to 30 seconds.
timeout: seconds each attempt may take, a positive number.
from ovok_sdk import Ovok
ovok = Ovok("https://api.sandbox.ovok.com", "{{TENANT_CODE}}", timeout=10)Override the timeout for one callServer-side
Pass options=RequestOptions(timeout=...) to the method. Every namespace method that sends a request takes options as a keyword argument, and it changes that call only.
timeout: seconds each attempt may take;Nonekeeps the client's.
from ovok_sdk import RequestOptions
health = ovok.health.check(options=RequestOptions(timeout=2))
print(health["ok"])The timeout covers each attempt. Retries, the resend after a token refresh, and the later pages of a Page keep it.
Verify your integration: the script prints True.
Handle a timeoutServer-side
A request that gets no answer in time raises OvokTimeoutError, a subclass of OvokConnectionError. Safe requests are retried first, so the error reaches you after the retries.
from ovok_sdk import OvokTimeoutError, RequestOptions
try:
patients = ovok.slim.patients.list({"count": 20}, options=RequestOptions(timeout=5))
except OvokTimeoutError:
patients = Noneovok.measurements.save takes RequestOptions inside its save options instead; see Measurements.
Test your integration
- Call
ovok.health.checkwith a two-second timeout and confirm it answers. - Build
RequestOptions(timeout=0)and confirm it raisesOvokConfigError. - Call a client whose
base_urldoes not answer with a one-second timeout and confirmOvokTimeoutError.
| Scenario | How to trigger | Expected result |
|---|---|---|
| Per-call timeout | Call ovok.health.check(options=RequestOptions(timeout=2)) | The health result is returned. |
| Invalid timeout | Build RequestOptions(timeout=0) | OvokConfigError is raised. |
| No answer | Build the client with a base_url that does not answer and call it with RequestOptions(timeout=1) | OvokTimeoutError is raised after the retries. |
See also
Last updated on