{"record":{"id":"2a0c277a68ca0514","repo":"geekcomputers/Python","slug":"something-go-wrong-with-getting-the-word-from-site","errorCode":null,"errorMessage":"Something go wrong with getting the word from site","messagePattern":"Something go wrong with getting the word from site","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Industrial_developed_hangman/src/hangman/main.py","lineNumber":82,"sourceCode":"def 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.\n        \"\"\"\n        self._source = source\n        self._answer_word = \"\"","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Industrial_developed_hangman/src/hangman/main.py#L64-L100","documentation":"parse_word_from_site raises RuntimeError when the HTTP request completed but the response status code is not the expected success code (200). The API is reachable but did not return a word, so the result cannot be parsed.","triggerScenarios":"random-word-api.herokuapp.com returning 4xx/5xx (rate limit 429, 500), the API being down or its route changed, or a custom url argument returning non-200.","commonSituations":"Free public APIs rate-limiting bursts of requests; the third-party API changing or disappearing; passing a wrong URL parameter in custom setups.","solutions":["Retry with backoff, especially for 429/5xx responses","Cache words locally or switch to Source.FROM_FILE as a fallback","Verify the url parameter points to the current API endpoint","Log response.status_code and body to diagnose which failure occurred"],"exampleFix":"# before\nword = get_word(Source.FROM_INTERNET)\n# after\nfor attempt in range(3):\n    try:\n        word = get_word(Source.FROM_INTERNET)\n        break\n    except RuntimeError:\n        time.sleep(2 ** attempt)\nelse:\n    word = get_word(Source.FROM_FILE)","handlingStrategy":"retry","validationCode":"# pre-check endpoint health\nimport requests\nok = requests.head('https://random-word-api.herokuapp.com/word', timeout=5).status_code == 200","typeGuard":null,"tryCatchPattern":"for delay in (1, 2, 4):\n    try:\n        word = get_word(Source.FROM_INTERNET)\n        break\n    except RuntimeError:\n        time.sleep(delay)\nelse:\n    word = get_word(Source.FROM_FILE)","preventionTips":["Retry transient 429/5xx with exponential backoff","Keep Source.FROM_FILE as a permanent fallback","Log status codes to distinguish rate limits from outages"],"tags":["hangman","http-error","api","runtime-error"],"backgroundTag":"http-unexpected-status","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}