geekcomputers/Python · error · ConnectionError
There is no connection to the internet
Error message
There is no connection to the internet
What it means
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).
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
Example fix
# before
word = get_word(Source.FROM_INTERNET)
# after
try:
word = get_word(Source.FROM_INTERNET)
except ConnectionError:
word = get_word(Source.FROM_FILE) Defensive patterns
Strategy: fallback
Validate before calling
import socket
def has_internet(host='8.8.8.8', port=53, timeout=2) -> bool:
try:
socket.create_connection((host, port), timeout)
return True
except OSError:
return False Try / catch
try:
word = get_word(Source.FROM_INTERNET)
except ConnectionError:
word = get_word(Source.FROM_FILE) Prevention
- Prefer the offline file source in sandboxed/CI environments
- Configure proxy env vars in corporate networks
- Cache fetched words for reuse
When it happens
Trigger: 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.
Common situations: CI runners without network, airplane-mode laptops, corporate proxies requiring auth, the API host being blocked or unreachable.
Related errors
- File local_words.txt was not found
- Non existing enum
- Something go wrong with getting the word from site
AI-assisted analysis of geekcomputers/Python@40f4cd2652 (2026-08-27).
Data as JSON: /api/errors/9051fa081ce13720.
Report an issue: GitHub.
Appendix: source
Thrown at Industrial_developed_hangman/src/hangman/main.py:79
raise FileNotFoundError("File local_words.txt was not found")
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.View on GitHub (pinned to 40f4cd2652)