GNews
raw JSON → 0.4.3 verified Fri May 01 auth: no python
A lightweight Python client to search and retrieve news articles from Google News, returning structured JSON. Current version 0.4.3. Low release cadence, last release in 2021.
pip install gnews Common errors
error ModuleNotFoundError: No module named 'gnews' ↓
cause Package not installed or wrong import path.
fix
Run
pip install gnews and use from gnews import GNEWS. error AttributeError: module 'gnews' has no attribute 'GNEWS' ↓
cause Possibly a different library with same name, or incorrect import statement.
fix
Ensure you installed the correct package:
pip uninstall gnews then pip install gnews. Then import with from gnews import GNEWS. error TypeError: 'NoneType' object is not iterable ↓
cause `get_news()` returned None due to network error or empty search results.
fix
Check network connectivity and handle None:
results = gnews.get_news('query') or []. Warnings
breaking Version 0.2.3 changed the method signature. `GNEWS.get_news(query)` now returns a list of dicts instead of a dict with 'entries' key. ↓
fix Update code to handle list directly, not accessing .get('entries').
gotcha The class name is `GNEWS` (all caps), not `Gnews` or `GNews`. Many examples online use incorrect casing. ↓
fix Use `from gnews import GNEWS`.
deprecated The `get_news_by_topic` method is no longer documented and may be removed in future versions. ↓
fix Use `get_news(query)` with appropriate keywords instead.
gotcha Google News may block requests without proper User-Agent. The library does not set one by default. ↓
fix Manually set headers on the session: `gnews.session.headers.update({'User-Agent': 'Mozilla/5.0 ...'})`.
breaking The `country` parameter in constructor expects ISO 3166-1 alpha-2 code (e.g., 'US', 'IN'). Wrong codes may silently return empty results. ↓
fix Use valid country codes. Common ones: 'US', 'GB', 'IN', 'CA'.
Imports
- GNEWS wrong
from gnews import Gnewscorrectfrom gnews import GNEWS - GNEWS wrong
from gnews_client import GNEWScorrectfrom gnews import GNEWS - GNEWS wrong
import gnewscorrectfrom gnews import GNEWS
Quickstart
from gnews import GNEWS
# Initialize with optional language and country
gnews = GNEWS(language='en', country='US')
# Search for news
results = gnews.get_news('Python programming')
for article in results[:3]:
print(article['title'], '-', article['url'])