{"record":{"id":"7fa99db74abd10e7","repo":"mem0ai/mem0","slug":"net-connect","errorCode":"NET_CONNECT","errorMessage":"Connection failed: {str(e)}","messagePattern":"Connection failed: (.+?)","errorType":"exception","errorClass":"NetworkError","httpStatus":null,"severity":"error","filePath":"mem0/client/utils.py","lineNumber":79,"sourceCode":"        status_code=e.response.status_code,\n        response_text=response_text,\n        details=error_details,\n        debug_info=debug_info,\n    )\n\n\ndef _handle_request_error(e):\n    logger.error(f\"Request error occurred: {e}\")\n\n    if isinstance(e, httpx.TimeoutException):\n        raise NetworkError(\n            message=f\"Request timed out: {str(e)}\",\n            error_code=\"NET_TIMEOUT\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"timeout\", \"original_error\": str(e)},\n        )\n    elif isinstance(e, httpx.ConnectError):\n        raise NetworkError(\n            message=f\"Connection failed: {str(e)}\",\n            error_code=\"NET_CONNECT\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"connection\", \"original_error\": str(e)},\n        )\n    else:\n        raise NetworkError(\n            message=f\"Network request failed: {str(e)}\",\n            error_code=\"NET_GENERIC\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"request\", \"original_error\": str(e)},\n        )\n\n\ndef api_error_handler(func):\n    \"\"\"Decorator to handle API errors consistently.\n\n    This decorator catches HTTP and request errors and converts them to","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/client/utils.py#L61-L97","documentation":"The client-side translation of httpx.ConnectError into NetworkError with error_code NET_CONNECT, produced by the api_error_handler decorator. It means the TCP/TLS connection to the Mem0 API could not be established at all; the message embeds httpx's original error string (e.g. DNS failure, connection refused).","triggerScenarios":"Any decorated API call when DNS resolution fails, the host is unreachable, a proxy refuses the connection, or TLS handshake fails. Commonly '[Errno -2] Name or service not known' or 'Connection refused' inside the message.","commonSituations":"Typos or custom base_url overrides; running in sandboxes/containers without DNS or egress; corporate proxies requiring HTTP_PROXY/HTTPS_PROXY env vars; firewall blocking api.mem0.ai; offline development.","solutions":["Verify network egress to the API host (curl https://api.mem0.ai) from the same environment","Fix any custom base_url typo or remove it to use the default","Set HTTPS_PROXY/HTTP_PROXY if behind a corporate proxy","If offline intentionally, switch to the open-source self-hosted Memory class instead of the hosted client"],"exampleFix":"# before\nclient = MemoryClient(base_url=\"https://api.mem0.ai/\", api_key=API_KEY)  # blocked network\n\n# after\nexport HTTPS_PROXY=http://proxy.corp:8080\nclient = MemoryClient(api_key=API_KEY)","handlingStrategy":"retry","validationCode":"import socket\n\ntry:\n    socket.getaddrinfo(\"api.mem0.ai\", 443)\nexcept OSError as e:\n    raise RuntimeError(f\"cannot reach api.mem0.ai: {e}; check DNS/proxy/egress\")","typeGuard":"def is_connect_error(err) -> bool:\n    return getattr(err, \"error_code\", None) == \"NET_CONNECT\"","tryCatchPattern":"try:\n    client.get_all(user_id=uid)\nexcept NetworkError as e:\n    if e.error_code == \"NET_CONNECT\":\n        logger.error(\"no route to API: %s\", e.debug_info.get(\"original_error\"))\n        raise SystemExit(2)  # config/network problem; retrying won't help\n    raise","preventionTips":["Verify egress/DNS from the runtime environment before deploying (containers, CI, lambdas)","Configure proxy env vars explicitly in proxy-bound environments","Connection failures are not transient — fix the network instead of retrying blindly"],"tags":["network","connection","httpx","dns","proxy"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}