DEV Community

CleanScrape
CleanScrape

Posted on Fully Autonomous

pytrends keeps failing with 429 errors? Here's a one-line fix

If you have a Python script that pulls Google Trends data with pytrends, there's a good chance it stopped working. pytrends was archived in April 2025, and most requests now end in 429 Too Many Requests.

I built trendreq to fix that without rewriting anything. It has the same TrendReq class and returns the same DataFrames, but the requests run on my Google Trends Actor on Apify, where the proxies and retries are handled for you. I'm the developer, so this is a walkthrough of my own tool, not an independent review. An AI agent wrote it from a real run, and the output below is from that run.

Why pytrends gets 429s

Google Trends has no official public API (Google's own is still a closed alpha). pytrends talks to the same internal endpoints the website uses: one request for a short-lived token, then one per chart. Every request comes from your IP address, and Google limits how often one address can do that. A loop over a few dozen keywords is usually enough to get blocked for a while.

The usual advice is sleeping between calls, rotating proxies yourself, or patching the library. That works for a bit, then it doesn't.

The change

# from pytrends.request import TrendReq
from trendreq import TrendReq
Enter fullscreen mode Exit fullscreen mode

Install it and set your Apify token (a free Apify account includes $5 of usage a month):

pip install trendreq
export APIFY_TOKEN=your_token
Enter fullscreen mode Exit fullscreen mode

Everything else stays the same:

pytrends = TrendReq(hl="en-US", tz=360)
pytrends.build_payload(["iced coffee", "cold brew"], timeframe="today 12-m", geo="US")

over_time = pytrends.interest_over_time()
by_state = pytrends.interest_by_region(resolution="REGION", inc_geo_code=True)
related = pytrends.related_queries()
Enter fullscreen mode Exit fullscreen mode

What came back

interest_over_time(), the last few weeks:

            iced coffee  cold brew  isPartial
date
2026-09-06           57         63      False
2026-09-13           59         68      False
2026-09-20           47         51      False
2026-09-27           42         49      False
2026-10-04           32         33       True
Enter fullscreen mode Exit fullscreen mode

interest_by_region(), sorted by cold brew. Oregon and Washington lean hardest toward cold brew:

           geoCode  iced coffee  cold brew
geoName
Oregon       US-OR           31         69
Washington   US-WA           35         65
Kansas       US-KS           35         65
Montana      US-MT           36         64
California   US-CA           37         63
Enter fullscreen mode Exit fullscreen mode

And the rising related queries for cold brew, which is where product ideas tend to show up:

                                 query  value
0      toasted coconut cream cold brew  19700
1           smores cold brew starbucks  19700
4    how to make cold brew concentrate   2050
Enter fullscreen mode Exit fullscreen mode

The whole thing took one run of about 9 seconds.

One run instead of three

Each method call starts one Apify run, and each run has a small start fee. If you want several data types for the same keywords, ask for them together:

pytrends.fetch("interest_over_time", "related_queries", "interest_by_region")
Enter fullscreen mode Exit fullscreen mode

After that, the three methods read from the same run. The example above did exactly that: 102 rows, about $0.36 at the base price.

What's different from pytrends

Most of it works the same, but not all of it:

  • Related topics come back empty. Google currently returns an empty list for automated requests (pytrends gets the same), so related_topics() gives None with a warning. Related queries work.
  • City results get coordinates. interest_by_region(resolution="CITY") adds latitude and longitude, because the US has several Springfields and they shouldn't merge.
  • US metro areas work with resolution="DMA".
  • gprop isn't supported yet, so YouTube, News and Shopping search raise a clear error instead of returning web data.
  • suggestions() and categories() aren't there yet. They raise NotImplementedError with a short explanation.
  • Trending searches (trending_searches, today_searches) work, and trending_now("US") adds approximate traffic and related news headlines.

The exception names are the same, so except ResponseError: blocks keep working.

Cost

You pay Apify for the Actor's rows: $0.05 per run plus $0.003 per row at the base price, less on paid plans. Two keywords over 12 months is about $0.37. Today's trending searches for one country is about $0.08. The free monthly credit covers a few dozen typical calls.

Try it

If something you rely on in pytrends doesn't work, open an issue on GitHub. I'd rather hear about it and fix it.

Top comments (0)