{"record":{"id":"9051fa081ce13720","repo":"geekcomputers/Python","slug":"there-is-no-connection-to-the-internet","errorCode":null,"errorMessage":"There is no connection to the internet","messagePattern":"There is no connection to the internet","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"Industrial_developed_hangman/src/hangman/main.py","lineNumber":79,"sourceCode":"        raise FileNotFoundError(\"File local_words.txt was not found\")\n\n\ndef parse_word_from_site(\n    url: str = \"https://random-word-api.herokuapp.com/word\",\n) -> str:\n    # noqa: DAR201\n    \"\"\"\n    Parse word from website.\n\n    :param url: url that word will be parsed from.\n    :return Optional[str]: string that contains the word.\n    :raises ConnectionError: no connection to the internet.\n    :raises RuntimeError: something go wrong with getting the word from site.\n    \"\"\"\n    try:\n        response: requests.Response = requests.get(url, timeout=request_timeout)\n    except ConnectionError:\n        raise ConnectionError(\"There is no connection to the internet\")\n    if response.status_code == success_code:\n        return json.loads(response.content.decode())[0]\n    raise RuntimeError(\"Something go wrong with getting the word from site\")\n\n\nclass MainProcess(object):\n    \"\"\"Manages game process.\"\"\"\n\n    def __init__(\n        self, source: Enum, pr_func: Callable, in_func: Callable, ch_func: Callable\n    ) -> None:\n        \"\"\"\n        Init MainProcess object.\n\n        :parameter in_func: Function that will be used to get input in game.\n        :parameter source: Represents source to get word.\n        :parameter pr_func: Function that will be used to print in game.\n        :parameter ch_func: Function that will be used to choice word.","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Industrial_developed_hangman/src/hangman/main.py#L61-L97","documentation":"parse_word_from_site wraps requests.get and re-raises ConnectionError with a clear message when the machine has no internet connectivity. It is the first of three failure modes for the online word source (no connection, bad status, decode errors).","triggerScenarios":"get_word with Source.FROM_INTERNET while offline, DNS fails, or a proxy/firewall blocks the request to random-word-api.herokuapp.com. Note: requests raises ConnectionError for many network-layer failures, and timeouts raise Timeout (a subclass), so both can land here.","commonSituations":"CI runners without network, airplane-mode laptops, corporate proxies requiring auth, the API host being blocked or unreachable.","solutions":["Check connectivity / proxy env vars (HTTP_PROXY, HTTPS_PROXY) before running","Fall back to Source.FROM_FILE when ConnectionError is caught","Retry with backoff for transient drops","For tests, mock requests.get or point url at a local server"],"exampleFix":"# before\nword = get_word(Source.FROM_INTERNET)\n# after\ntry:\n    word = get_word(Source.FROM_INTERNET)\nexcept ConnectionError:\n    word = get_word(Source.FROM_FILE)","handlingStrategy":"fallback","validationCode":"import socket\ndef has_internet(host='8.8.8.8', port=53, timeout=2) -> bool:\n    try:\n        socket.create_connection((host, port), timeout)\n        return True\n    except OSError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    word = get_word(Source.FROM_INTERNET)\nexcept ConnectionError:\n    word = get_word(Source.FROM_FILE)","preventionTips":["Prefer the offline file source in sandboxed/CI environments","Configure proxy env vars in corporate networks","Cache fetched words for reuse"],"tags":["hangman","network","connection-error","requests"],"backgroundTag":"no-internet-connection","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}