{"record":{"id":"968806441cf84d38","repo":"PaddlePaddle/PaddleOCR","slug":"connection-failed-e-968806","errorCode":null,"errorMessage":"Connection failed: {e}","messagePattern":"Connection failed: (.+?)","errorType":"exception","errorClass":"NetworkError","httpStatus":null,"severity":"error","filePath":"paddleocr/_api_client/_resources.py","lineNumber":52,"sourceCode":") -> str:\n    if not resource_url:\n        raise InvalidRequestError(\"resource_url is required.\")\n    if not destination:\n        raise InvalidRequestError(\"destination is required.\")\n\n    parsed_url = urlparse(resource_url)\n    if parsed_url.scheme not in (\"http\", \"https\") or not parsed_url.netloc:\n        raise InvalidRequestError(f\"Invalid resource URL: {resource_url}\")\n\n    target = _resolve_destination(parsed_url.path, destination, filename)\n    _require_writable_target(target, overwrite)\n\n    try:\n        response = requests.get(resource_url, timeout=timeout)\n    except requests.Timeout as e:\n        raise RequestTimeoutError(f\"Request timed out: {e}\") from e\n    except requests.ConnectionError as e:\n        raise NetworkError(f\"Connection failed: {e}\") from e\n\n    try:\n        response.raise_for_status()\n    except requests.RequestException as e:\n        raise NetworkError(f\"Failed to download resource: {e}\") from e\n\n    _atomic_write(target, response.content, overwrite)\n    return str(target)\n\n\ndef save_ocr_result_resources(\n    result: OCRResult,\n    destination: str,\n    *,\n    overwrite: bool = False,\n    timeout: float = 300.0,\n) -> List[str]:\n    if result is None:","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_api_client/_resources.py#L34-L70","documentation":"NetworkError raised when requests.get for a result resource throws requests.ConnectionError: DNS failure, refused connection, TLS handshake failure, or a dropped connection. It fires before any status check; the chained exception carries the underlying cause.","triggerScenarios":"save_resource with a result URL whose host does not resolve, is unreachable from the client network, uses a certificate the client rejects, or where the connection is reset mid-download (requests maps reset-after-connect to ConnectionError).","commonSituations":"Result URLs pointing at an internal host not reachable from where the client runs (VPN split-tunnel); expired DNS for ephemeral result-storage domains; corporate TLS inspection breaking the handshake; result storage service briefly down.","solutions":["Verify reachability: curl the resource URL from the same machine/network","If the host is internal, run the client inside the network/VPN or mirror the artifacts to a reachable host","For TLS issues, install the proxy/inspection CA into the client environment's trust store","Retry with backoff for transient resets (connection issues are often intermittent)"],"exampleFix":"# before\nfor url in urls:\n    save_resource(url, dest)  # first reset kills the batch\n\n# after\nfor url in urls:\n    for attempt in range(3):\n        try:\n            save_resource(url, dest); break\n        except NetworkError:\n            if attempt == 2: raise\n            time.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":"import socket\nsocket.gethostbyname(urlparse(url).hostname)  # pre-flight DNS check","typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        save_resource(url, dest)\n        break\n    except NetworkError as e:\n        if attempt == 2 or 'Connection failed' not in str(e): raise\n        time.sleep(2 ** attempt)","preventionTips":["Verify the result-storage host is reachable from the client's network before large batch runs","Run downloads in the same network segment that completed the API calls","Keep retry with exponential backoff around every result download"],"tags":["network","download","connection"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}