Wulfcare Data guides

pytrends 429 TooManyRequestsError: how to fix it

This is the error nearly everyone using pytrends eventually hits:

pytrends.exceptions.TooManyRequestsError: The request failed: Google returned a response with code 429

Why it happens

pytrends sends every request from your own IP address. Google Trends rate-limits an IP after a handful of requests, then answers everything with HTTP 429.

sleep(), retries= and backoff_factor= only slow you down, so they rarely solve it. The pytrends repository is also archived on GitHub, so a fix isn't coming from there.

Fix 1: swap the import

pytrends_alternative.py keeps the pytrends interface but runs each query on a hosted Google Trends Scraper, which spreads requests over many IPs.

pip install apify-client pandas
export APIFY_TOKEN=apify_api_...

Copy the file next to your code, then change one line:

# from pytrends.request import TrendReq
from pytrends_alternative import TrendReq

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

df = pytrends.interest_over_time()   # date index, one column per keyword, isPartial

interest_by_region() and related_queries() work the same way. It costs $0.003 per report, and Apify's free plan includes $5 of credit a month. Get a token from a free Apify account under Settings → API & Integrations.

Fix 2: rotate proxies yourself

pytrends accepts a proxies list, so you can bring your own pool and keep using it. You'll need to find proxies Google isn't already limiting, and replace them as they get blocked.

Fix 3: use less data

For a one-off job, you may only need to spread a few requests out over a longer time, or download the CSV from the Google Trends website by hand.

Two things pytrends can't do

These combined figures are estimates built from several Google queries, so treat small terms with care.