{"record":{"id":"e78da582ee99c207","repo":"abi/screenshot-to-code","slug":"an-error-occurred-while-requesting-exc","errorCode":null,"errorMessage":"An error occurred while requesting: {exc}","messagePattern":"An error occurred while requesting: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/image_generation/replicate.py","lineNumber":95,"sourceCode":"    endpoint_url: str, payload: dict[str, Any], api_token: str\n) -> Any:\n    headers = _build_headers(api_token)\n\n    async with httpx.AsyncClient() as client:\n        try:\n            response = await client.post(endpoint_url, headers=headers, json=payload)\n            response.raise_for_status()\n            response_json = response.json()\n            if not isinstance(response_json, dict):\n                raise ValueError(\"Invalid prediction creation response.\")\n\n            prediction_id = _extract_prediction_id(response_json)\n            final_response = await _poll_prediction(client, prediction_id, headers)\n            return final_response.get(\"output\")\n        except httpx.HTTPStatusError as exc:\n            raise ValueError(f\"HTTP error occurred: {exc}\") from exc\n        except httpx.RequestError as exc:\n            raise ValueError(f\"An error occurred while requesting: {exc}\") from exc\n        except asyncio.TimeoutError as exc:\n            raise TimeoutError(\"Request timed out\") from exc\n        except (TimeoutError, ValueError):\n            raise\n        except Exception as exc:\n            raise ValueError(f\"An unexpected error occurred: {exc}\") from exc\n\n\ndef _extract_output_url(result: Any, context: str) -> str:\n    if isinstance(result, str):\n        return result\n\n    if isinstance(result, dict):\n        url = cast(Any, result.get(\"url\"))\n        if isinstance(url, str) and url:\n            return url\n\n    if isinstance(result, list) and len(result) > 0:","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/image_generation/replicate.py#L77-L113","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check `exc.__cause__` for the specific httpx error class (ConnectError vs ReadError vs ConnectTimeout).","Verify network egress: curl https://api.replicate.com from the same host/container.","Configure trusted CA certs (SSL_CERT_FILE or REQUESTS_CA_BUNDLE style fixes) behind TLS-intercepting proxies.","Retry transient ReadErrors — polling can resume by re-creating the prediction."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    output = await call_replicate_model(model, input, token)\nexcept ValueError as e:\n    if isinstance(e.__cause__, httpx.RequestError):\n        if isinstance(e.__cause__, httpx.ConnectError):\n            return error(\"Cannot reach api.replicate.com — check egress/DNS\")\n        await asyncio.sleep(2)  # transient read error: retry once\n        output = await call_replicate_model(model, input, token)\n    else:\n        raise","preventionTips":["Verify egress with curl https://api.replicate.com before debugging code","Install the corporate CA bundle on TLS-intercepting networks","Retry only transient httpx errors (ReadError/RemoteProtocolError), never ConnectError"],"tags":["replicate","network","http","proxy","image-generation"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}