abi/screenshot-to-code · error · ValueError

An error occurred while requesting: {exc}

Error message

An error occurred while requesting: {exc}

What it means

Wrapped error from _run_prediction: an httpx.RequestError (network-level failure before any HTTP response — DNS failure, connection refused, TLS error, read timeout on the socket) is re-raised as ValueError with the underlying exception text. The original is chained via `from exc`. It covers both the initial POST and the polling GETs since both run inside the same try block.

Source

Thrown at backend/image_generation/replicate.py:95

    endpoint_url: str, payload: dict[str, Any], api_token: str
) -> Any:
    headers = _build_headers(api_token)

    async with httpx.AsyncClient() as client:
        try:
            response = await client.post(endpoint_url, headers=headers, json=payload)
            response.raise_for_status()
            response_json = response.json()
            if not isinstance(response_json, dict):
                raise ValueError("Invalid prediction creation response.")

            prediction_id = _extract_prediction_id(response_json)
            final_response = await _poll_prediction(client, prediction_id, headers)
            return final_response.get("output")
        except httpx.HTTPStatusError as exc:
            raise ValueError(f"HTTP error occurred: {exc}") from exc
        except httpx.RequestError as exc:
            raise ValueError(f"An error occurred while requesting: {exc}") from exc
        except asyncio.TimeoutError as exc:
            raise TimeoutError("Request timed out") from exc
        except (TimeoutError, ValueError):
            raise
        except Exception as exc:
            raise ValueError(f"An unexpected error occurred: {exc}") from exc


def _extract_output_url(result: Any, context: str) -> str:
    if isinstance(result, str):
        return result

    if isinstance(result, dict):
        url = cast(Any, result.get("url"))
        if isinstance(url, str) and url:
            return url

    if isinstance(result, list) and len(result) > 0:

View on GitHub (pinned to d026163f58)

Solutions

  1. Check `exc.__cause__` for the specific httpx error class (ConnectError vs ReadError vs ConnectTimeout).
  2. Verify network egress: curl https://api.replicate.com from the same host/container.
  3. Configure trusted CA certs (SSL_CERT_FILE or REQUESTS_CA_BUNDLE style fixes) behind TLS-intercepting proxies.
  4. Retry transient ReadErrors — polling can resume by re-creating the prediction.
Defensive patterns

Strategy: retry

Try / catch

try:
    output = await call_replicate_model(model, input, token)
except ValueError as e:
    if isinstance(e.__cause__, httpx.RequestError):
        if isinstance(e.__cause__, httpx.ConnectError):
            return error("Cannot reach api.replicate.com — check egress/DNS")
        await asyncio.sleep(2)  # transient read error: retry once
        output = await call_replicate_model(model, input, token)
    else:
        raise

Prevention

When it happens

Trigger: No egress to api.replicate.com (firewall/air-gapped env); DNS resolution failure; TLS interception with an untrusted corporate CA; the connection dropping mid-poll so a GET raises httpx.ConnectError/ReadError instead of returning a status.

Common situations: Corporate proxies blocking outbound HTTPS; sandboxed CI without network access; flaky connections dropping long polling sessions; self-signed MITM proxies not in the trust store.

Related errors


AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14). Data as JSON: /api/errors/e78da582ee99c207. Report an issue: GitHub.