xtekky/gpt4free · warning · VersionNotFoundError
Failed to get PyPI version for '{package_name}'
Error message
Failed to get PyPI version for '{package_name}' What it means
get_latest_pypi_version in g4f/version.py raises VersionNotFoundError when fetching https://pypi.org/pypi/{package}/json fails for any reason: network error, non-2xx status (raise_for_status), missing 'info.version' key, or a JSON parse error. The original exception is chained via 'from e'.
Source
Thrown at g4f/version.py:34
@lru_cache(maxsize=1)
def get_pypi_version(package_name: str) -> str:
"""
Retrieves the latest version of a package from PyPI.
Raises:
VersionNotFoundError: If there is a network or parsing error.
"""
try:
import requests
response = requests.get(
f"https://pypi.org/pypi/{package_name}/json", timeout=REQUEST_TIMEOUT
)
response.raise_for_status()
return response.json()["info"]["version"]
except Exception as e:
raise VersionNotFoundError(
f"Failed to get PyPI version for '{package_name}'"
) from e
@lru_cache(maxsize=1)
def get_github_version(repo: str) -> str:
"""
Retrieves the latest release version from a GitHub repository.
Raises:
VersionNotFoundError: If there is a network or parsing error.
"""
try:
import requests
response = requests.get(
f"https://api.github.com/repos/{repo}/releases/latest",
timeout=REQUEST_TIMEOUT,View on GitHub (pinned to 973504e177)
Solutions
- Check network connectivity and proxy settings so https://pypi.org/pypi/<pkg>/json is reachable
- Verify the package name exists on PyPI (a 404 triggers raise_for_status)
- Catch VersionNotFoundError and fall back to the locally known version instead of crashing the update check
- Retry after a short delay for transient PyPI errors; pin to cached results (the function is not cached, unlike get_github_version)
Example fix
# before
version = get_latest_pypi_version('g4f') # raises if offline
# after
from g4f.version import get_latest_pypi_version, VersionNotFoundError
try:
version = get_latest_pypi_version('g4f')
except VersionNotFoundError:
version = None # skip update check Defensive patterns
Strategy: try-catch
Validate before calling
import socket, urllib.request
def pypi_reachable(timeout=3) -> bool:
try:
urllib.request.urlopen("https://pypi.org/pypi/g4f/json", timeout=timeout)
return True
except Exception:
return False Try / catch
from g4f.version import get_latest_pypi_version, VersionNotFoundError
try:
latest = get_latest_pypi_version("g4f")
except VersionNotFoundError as e:
latest = None # inspect e.__cause__ for the underlying network error Prevention
- Treat version checks as best-effort: always catch VersionNotFoundError
- Cache or skip update checks in offline/CI environments
- Confirm package names exist on PyPI before querying
When it happens
Trigger: Calling get_latest_pypi_version('g4f') (directly or through an update-check helper) while offline, behind a proxy that blocks pypi.org, when PyPI rate-limits or 404s the package, or when the response body is truncated/invalid JSON.
Common situations: Air-gapped or corporate-proxy environments; DNS failures; checking a package name that does not exist on PyPI; transient PyPI outages during update checks.
Related errors
- No tag_name found in latest GitHub release for '{repo}'
- Failed to get GitHub release version for '{repo}'
- CDP module is required for Cloudflare provider. Please ensur
- WebSocket Error: {ws.exception()}
- Yupp request failed: {str(e)}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/18d5a6e7c5aa4403.
Report an issue: GitHub.