geekcomputers/Python · error · RuntimeError

Something go wrong with getting the word from site

Error message

Something go wrong with getting the word from site

What it means

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.

Source

Thrown at Industrial_developed_hangman/src/hangman/main.py:82

def parse_word_from_site(
    url: str = "https://random-word-api.herokuapp.com/word",
) -> str:
    # noqa: DAR201
    """
    Parse word from website.

    :param url: url that word will be parsed from.
    :return Optional[str]: string that contains the word.
    :raises ConnectionError: no connection to the internet.
    :raises RuntimeError: something go wrong with getting the word from site.
    """
    try:
        response: requests.Response = requests.get(url, timeout=request_timeout)
    except ConnectionError:
        raise ConnectionError("There is no connection to the internet")
    if response.status_code == success_code:
        return json.loads(response.content.decode())[0]
    raise RuntimeError("Something go wrong with getting the word from site")


class MainProcess(object):
    """Manages game process."""

    def __init__(
        self, source: Enum, pr_func: Callable, in_func: Callable, ch_func: Callable
    ) -> None:
        """
        Init MainProcess object.

        :parameter in_func: Function that will be used to get input in game.
        :parameter source: Represents source to get word.
        :parameter pr_func: Function that will be used to print in game.
        :parameter ch_func: Function that will be used to choice word.
        """
        self._source = source
        self._answer_word = ""

View on GitHub (pinned to 40f4cd2652)

Solutions

  1. Retry with backoff, especially for 429/5xx responses
  2. Cache words locally or switch to Source.FROM_FILE as a fallback
  3. Verify the url parameter points to the current API endpoint
  4. Log response.status_code and body to diagnose which failure occurred

Example fix

# before
word = get_word(Source.FROM_INTERNET)
# after
for attempt in range(3):
    try:
        word = get_word(Source.FROM_INTERNET)
        break
    except RuntimeError:
        time.sleep(2 ** attempt)
else:
    word = get_word(Source.FROM_FILE)
Defensive patterns

Strategy: retry

Validate before calling

# pre-check endpoint health
import requests
ok = requests.head('https://random-word-api.herokuapp.com/word', timeout=5).status_code == 200

Try / catch

for delay in (1, 2, 4):
    try:
        word = get_word(Source.FROM_INTERNET)
        break
    except RuntimeError:
        time.sleep(delay)
else:
    word = get_word(Source.FROM_FILE)

Prevention

When it happens

Trigger: 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.

Common situations: Free public APIs rate-limiting bursts of requests; the third-party API changing or disappearing; passing a wrong URL parameter in custom setups.

Related errors


AI-assisted analysis of geekcomputers/Python@40f4cd2652 (2026-08-27). Data as JSON: /api/errors/2a0c277a68ca0514. Report an issue: GitHub.