Menu

pytrends keeps failing with 429? A drop-in replacement that changes one import
📰

pytrends keeps failing with 429? A drop-in replacement that changes one import

DEV Community: datascience·bibian·3 days ago
#COQFrPKy
#devtodatascience#science#devto#dev#pytrends
Reading 0:00
15s threshold

If you pull Google Trends data in Python, you have probably seen this one:

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

Enter fullscreen mode

Exit fullscreen mode

pytrends is still downloaded more than a million times a month on PyPI, but its repository is archived: nobody fixes it anymore, and Google rate-limits it per IP address. Sleeping between calls, rotating user agents or adding retries= only pushes the problem back.

I wrote pytrends-cloud to keep the pytrends API and swap the transport. Your code stays the same; the requests to Google run in the cloud, where 429s are retried with backoff and rotating proxies instead of crashing your script.

Change one import

# from pytrends.request import TrendReq from pytrends_cloud import TrendReq

pytrends = TrendReq ( hl = "en-US" , tz = 360 ) pytrends . build_payload ( [ "python" , "javascript" , "rust" ] , timeframe = "today 12-m" ) print ( pytrends . interest_over_time ( ) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.