Guides

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.
client.py
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; None keeps the client's.
quick_check.py
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.

timeout.py
from ovok_sdk import OvokTimeoutError, RequestOptions

try:
    patients = ovok.slim.patients.list({"count": 20}, options=RequestOptions(timeout=5))
except OvokTimeoutError:
    patients = None

ovok.measurements.save takes RequestOptions inside its save options instead; see Measurements.

Test your integration

  1. Call ovok.health.check with a two-second timeout and confirm it answers.
  2. Build RequestOptions(timeout=0) and confirm it raises OvokConfigError.
  3. Call a client whose base_url does not answer with a one-second timeout and confirm OvokTimeoutError.
ScenarioHow to triggerExpected result
Per-call timeoutCall ovok.health.check(options=RequestOptions(timeout=2))The health result is returned.
Invalid timeoutBuild RequestOptions(timeout=0)OvokConfigError is raised.
No answerBuild 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

On this page