---
title: "Errors, timeouts, and retries"
description: "Handle errors by kind, choose time limits, and retry requests safely."
canonical_url: "https://docs.flashdrive.space/sdk/errors-and-retries"
---
# Errors, timeouts, and retries

> Handle errors by kind, choose time limits, and retry requests safely.

These examples use the latest stable release of the Python SDK.

Every API failure raises a `FlashdriveError` or one of its subclasses. Invalid arguments are caught before anything is sent and raise `ValueError`.

## Inspect an error

```python
from flashdrive import Flashdrive, FlashdriveError

with Flashdrive(drive_id="DRIVE_UUID") as client:
    try:
        client.files.edit_text(
            "DOCUMENT_UUID",
            [("draft", "final")],
            revision="7",
            idempotency_key="finalize-1",
        )
    except FlashdriveError as exc:
        print(exc.status, exc.code, exc.request_id, exc.details)
        print(exc.error_type, exc.retryable, exc.retry_key, exc.retry_after)
```

Every error has:

<table>
<thead>
  <tr>
    <th>
      Attribute
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        status
      </code>
    </td>
    
    <td>
      The HTTP status, or <code>
        None
      </code>
      
       for a failure inside the SDK.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        code
      </code>
    </td>
    
    <td>
      A stable code such as <code>
        stale_version
      </code>
      
       or <code>
        drive_limit_exceeded
      </code>
      
      . Decide on this, not on the message, whose wording can change.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        request_id
      </code>
    </td>
    
    <td>
      Quote it when you contact <a href="https://docs.flashdrive.space/reference/troubleshooting">
        support
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        details
      </code>
    </td>
    
    <td>
      More about the failure, such as the field or the index of a failed edit.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        retry_after
      </code>
    </td>
    
    <td>
      Seconds to wait before retrying, when the service says.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        error_type
      </code>
    </td>
    
    <td>
      The kind of problem, an <code>
        ErrorType
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        retryable
      </code>
    </td>
    
    <td>
      A <code>
        Retryable
      </code>
      
      : <code>
        never
      </code>
      
      , <code>
        after_backoff
      </code>
      
      , <code>
        after_retry_after
      </code>
      
       or <code>
        after_change
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        retry_key
      </code>
    </td>
    
    <td>
      A <code>
        RetryKey
      </code>
      
      : <code>
        same
      </code>
      
       to retry with the same idempotency key, <code>
        new
      </code>
      
       for a new one.
    </td>
  </tr>
</tbody>
</table>

Three properties sum these up: `is_retryable` (sending the request again can ever succeed), `retry_unchanged` (the same request can simply be sent again after a wait) and `retry_with_same_key`. The advice comes from the service's answer, then from the SDK's own list of codes, then from the HTTP status, so even a code newer than your SDK carries advice. Values the SDK does not know stay as the strings the service sent. See the [error reference](https://docs.flashdrive.space/reference/errors) for codes and messages.

## Handle a kind of problem

Each kind of error has its own class, so you can handle a kind of problem without knowing every code:

<table>
<thead>
  <tr>
    <th>
      Class
    </th>
    
    <th>
      <code>
        error_type
      </code>
    </th>
    
    <th>
      Typical cause
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        AuthenticationError
      </code>
    </td>
    
    <td>
      <code>
        auth
      </code>
    </td>
    
    <td>
      A missing, wrong or revoked key (<code>
        invalid_credentials
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        PermissionDeniedError
      </code>
    </td>
    
    <td>
      <code>
        permission
      </code>
    </td>
    
    <td>
      The key or token may not do this.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        NotFoundError
      </code>
    </td>
    
    <td>
      <code>
        not_found
      </code>
    </td>
    
    <td>
      The drive, folder or file does not exist, or is outside your access.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        InvalidRequestError
      </code>
    </td>
    
    <td>
      <code>
        invalid
      </code>
    </td>
    
    <td>
      A value the service refused.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ConflictError
      </code>
    </td>
    
    <td>
      <code>
        conflict
      </code>
    </td>
    
    <td>
      A name taken, an edit that does not apply, or work still in progress.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        PreconditionFailedError
      </code>
    </td>
    
    <td>
      <code>
        precondition
      </code>
    </td>
    
    <td>
      The file changed since you read it (<code>
        stale_version
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        RateLimitError
      </code>
    </td>
    
    <td>
      <code>
        rate_limit
      </code>
    </td>
    
    <td>
      Too many requests, or the drive's upload capacity is full.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        PaymentRequiredError
      </code>
    </td>
    
    <td>
      <code>
        payment_required
      </code>
    </td>
    
    <td>
      The workspace's plan or balance needs attention.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        QuotaExceededError
      </code>
    </td>
    
    <td>
      <code>
        quota
      </code>
    </td>
    
    <td>
      A drive or storage limit (<code>
        drive_limit_exceeded
      </code>
      
      , <code>
        storage_capacity_exceeded
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        RequestTooLargeError
      </code>
    </td>
    
    <td>
      <code>
        too_large
      </code>
    </td>
    
    <td>
      A file or request over its size limit.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ServiceUnavailableError
      </code>
    </td>
    
    <td>
      <code>
        unavailable
      </code>
    </td>
    
    <td>
      The service is busy or briefly unavailable.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        UpgradeRequiredError
      </code>
    </td>
    
    <td>
      <code>
        upgrade
      </code>
    </td>
    
    <td>
      This SDK version or API version is not supported.
    </td>
  </tr>
</tbody>
</table>

```python
import time
from flashdrive import ConflictError, PreconditionFailedError, RateLimitError

try:
    client.files.write_bytes(document_id, data, revision=revision, offset=0)
except PreconditionFailedError:
    ...  # the file changed: read it again, then decide
except ConflictError as exc:
    ...  # look at exc.code
except RateLimitError as exc:
    time.sleep(exc.retry_after or 1)
```

A throttled request raises `RateLimitError` with the message `Too many requests. Try again after HH:MM UTC.`

Other errors the SDK raises itself:

<table>
<thead>
  <tr>
    <th>
      Error
    </th>
    
    <th>
      When
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        SDKTimeoutError
      </code>
      
       (code <code>
        sdk_timeout
      </code>
      
      )
    </td>
    
    <td>
      A call ran out of its <code>
        timeout
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        UploadError
      </code>
    </td>
    
    <td>
      An upload failed after the service accepted it; <code>
        receipt
      </code>
      
       holds what to resume.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        UploadTimeoutError
      </code>
      
       (code <code>
        upload_timeout
      </code>
      
      )
    </td>
    
    <td>
      An upload's local wait ran out; it is both an <code>
        UploadError
      </code>
      
       and an <code>
        SDKTimeoutError
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        UploadBatchError
      </code>
      
       (code <code>
        upload_batch_failed
      </code>
      
      )
    </td>
    
    <td>
      Some files of an upload failed; see <a href="https://docs.flashdrive.space/sdk/upload-recovery">
        upload recovery
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        FileEditError
      </code>
    </td>
    
    <td>
      A <code>
        files.write_bytes()
      </code>
      
       call stopped. <code>
        idempotency_key
      </code>
      
      , <code>
        drive_id
      </code>
      
      , <code>
        document_id
      </code>
      
      , <code>
        base_revision
      </code>
      
       and <code>
        receipt
      </code>
      
       say how to resume: send the same data, options and revision with that key. A pending <code>
        receipt
      </code>
      
       does not prove the edit was saved.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        FileEditTimeoutError
      </code>
    </td>
    
    <td>
      A <code>
        files.write_bytes()
      </code>
      
       time limit ran out and the outcome is unknown; it is both a <code>
        FileEditError
      </code>
      
       and an <code>
        SDKTimeoutError
      </code>
      
      . Resume as above.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        BulkImportError
      </code>
    </td>
    
    <td>
      A bulk import stopped. <code>
        import_id
      </code>
      
      , <code>
        drive_id
      </code>
      
       and <code>
        journal
      </code>
      
       say how to resume, and <code>
        import_status
      </code>
      
       holds the last status, if known.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        SDKCompatibilityError
      </code>
    </td>
    
    <td>
      This SDK cannot work with the service's API.
    </td>
  </tr>
</tbody>
</table>

## Keep the SDK up to date

Two errors ask you to change your installed client or your code:

<table>
<thead>
  <tr>
    <th>
      Error
    </th>
    
    <th>
      HTTP status and code
    </th>
    
    <th>
      What to do
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ClientUpgradeRequiredError
      </code>
    </td>
    
    <td>
      426 <code>
        client_upgrade_required
      </code>
    </td>
    
    <td>
      This SDK version is below the oldest one the service supports. Check the available matching release in <a href="https://docs.flashdrive.space/sdk/installation">
        SDK setup
      </a>
      
       before upgrading. <code>
        exc.minimum_version
      </code>
      
       and <code>
        exc.latest_version
      </code>
      
       name the oldest supported and newest releases. It is an <code>
        SDKCompatibilityError
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        APIVersionRetiredError
      </code>
    </td>
    
    <td>
      410 <code>
        api_version_retired
      </code>
    </td>
    
    <td>
      The endpoint was retired on <code>
        exc.sunset_at
      </code>
      
      . Switch to <code>
        exc.replacement
      </code>
      
      , which can be <code>
        None
      </code>
      
      , and read the guide at <code>
        exc.docs_url
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

Before that happens, the SDK warns you once per notice and process: `SDKUpgradeWarning` when a newer release is available and `SDKDeprecationWarning` when something you use is deprecated, with the replacement, retirement date and upgrade command. Control them with Python's warning filters, or pass `version_warnings=False` to the client. The notices stay available in `client.notices`. The SDK never upgrades itself.

## Choose a time budget

Every call takes `timeout`, in seconds, for the whole call including retries:

<table>
<thead>
  <tr>
    <th>
      Call
    </th>
    
    <th>
      Default <code>
        timeout
      </code>
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Most calls
    </td>
    
    <td>
      30
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        upload()
      </code>
    </td>
    
    <td>
      600 for the transfers, plus <code>
        processing_timeout
      </code>
      
       600 for processing
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        documents.replace_file()
      </code>
      
      , <code>
        uploads.resume()
      </code>
      
      , recursive <code>
        folders.delete()
      </code>
    </td>
    
    <td>
      600
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        files.edit_text()
      </code>
    </td>
    
    <td>
      120
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        files.write_bytes()
      </code>
    </td>
    
    <td>
      120 per request, <code>
        processing_timeout
      </code>
      
       3600 overall
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        files.download()
      </code>
    </td>
    
    <td>
      120 for each range request
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        files.read_bytes()
      </code>
    </td>
    
    <td>
      60
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.ensure()
      </code>
    </td>
    
    <td>
      60
    </td>
  </tr>
</tbody>
</table>

Use `wait=False` on `upload()` and `replace_file()` to return once the service has accepted the work. Closing network connections can take a moment longer than the time limit. After a local timeout, use the original key or upload receipt to recover the result: work the service accepted continues.

## Automatic retries

The SDK retries a request only when repeating it is safe: reads, and changes that carry an idempotency key. It makes up to three attempts within the call's `timeout` for HTTP 429, 502, 503 and 504, for `request_in_progress`, and for dropped connections, waiting at least the `Retry-After` the service sends. If the wait a 429 asks for would outlast the deadline, the SDK raises the `RateLimitError` at once. After the last attempt, a dropped connection raises an error with code `transport_error`.

Calls that change files make their own idempotency key when you do not pass one, so the SDK's retries never apply a change twice. Pass your own `idempotency_key` when you want to retry the same change yourself, for example after your process restarts. A key is 1 to 128 visible ASCII characters.

### Wait for upload capacity

When a drive's upload capacity is full, the service answers 429 `upload_limit` or 409 `request_in_progress`. For uploads, the SDK waits and retries with the same key until the transfer deadline, following `Retry-After` and adding a small random delay to spread out clients. These waits do not use up the three attempts. Files waiting for capacity do not stop the rest of a batch.

For `storage_capacity_exceeded`, free space or increase your workspace's storage before retrying; see [storage and upgrades](https://docs.flashdrive.space/platform/storage-and-upgrades).

## Decide whether to reuse the key

<table>
<thead>
  <tr>
    <th>
      Outcome
    </th>
    
    <th>
      Next step
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The connection dropped before a reply arrived
    </td>
    
    <td>
      Retry the unchanged request with the same key to get the original result.
    </td>
  </tr>
  
  <tr>
    <td>
      The request is still running (<code>
        request_in_progress
      </code>
      
      )
    </td>
    
    <td>
      Wait, then retry with the same key.
    </td>
  </tr>
  
  <tr>
    <td>
      Rate limited
    </td>
    
    <td>
      Wait for <code>
        retry_after
      </code>
      
       and retry with the same key.
    </td>
  </tr>
  
  <tr>
    <td>
      The file changed (<code>
        stale_version
      </code>
      
      )
    </td>
    
    <td>
      Read it again, redo the change if it still applies, and use a new key.
    </td>
  </tr>
  
  <tr>
    <td>
      The service refused the input
    </td>
    
    <td>
      Correct it and use a new key for the changed request.
    </td>
  </tr>
  
  <tr>
    <td>
      The key was used with different details (<code>
        idempotency_conflict
      </code>
      
      )
    </td>
    
    <td>
      Send the original details, or use a new key.
    </td>
  </tr>
</tbody>
</table>

`exc.retry_key` gives the same advice for any error: `same` or `new`.


## Sitemap

See the full [sitemap](https://docs.flashdrive.space/sitemap.md) for all pages.
