<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Egrarobo</title>
    <description>The latest articles on DEV Community by Egrarobo (@egrarobo).</description>
    <link>https://dev.to/egrarobo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4149139%2F7cc7a9c4-c3db-436e-b770-3e45af97b8ee.png</url>
      <title>DEV Community: Egrarobo</title>
      <link>https://dev.to/egrarobo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/egrarobo"/>
    <language>en</language>
    <item>
      <title>pytrends keeps failing with 429 Too Many Requests? Here's a drop-in fix</title>
      <dc:creator>Egrarobo</dc:creator>
      <pubDate>Tue, 29 Sep 2026 09:01:16 +0000</pubDate>
      <link>https://dev.to/egrarobo/pytrends-keeps-failing-with-429-too-many-requests-heres-a-drop-in-fix-515</link>
      <guid>https://dev.to/egrarobo/pytrends-keeps-failing-with-429-too-many-requests-heres-a-drop-in-fix-515</guid>
      <description>&lt;p&gt;If you use &lt;strong&gt;pytrends&lt;/strong&gt; for Google Trends data, you have probably seen this more and more often:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pytrends.exceptions.TooManyRequestsError: The request failed: Google returned a response with code 429
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things changed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;pytrends was archived in April 2025.&lt;/strong&gt; The repository is read-only, so nobody is fixing the blocking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google's official Trends API is still in closed alpha&lt;/strong&gt; (announced July 2025), and access requests often go unanswered.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Meanwhile Google rate-limits Trends harder every year, especially from cloud servers, Colab and CI runners, which is exactly where most scripts run.&lt;/p&gt;

&lt;h2&gt;
  
  
  The usual workarounds (and why they break)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;time.sleep()&lt;/code&gt; between calls&lt;/strong&gt;: helps for a handful of keywords, fails for real workloads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;retries=&lt;/code&gt; and &lt;code&gt;backoff_factor=&lt;/code&gt;&lt;/strong&gt;: retrying from the same IP and the same cookies gets the same 429.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rotating proxies yourself&lt;/strong&gt;: works, but now you maintain proxies, cookies, consent pages and captchas instead of your analysis.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A drop-in replacement
&lt;/h2&gt;

&lt;p&gt;I wrote a small library that keeps the pytrends interface but moves the fragile part (sessions, proxies, retries) to a managed scraper. Every retry uses a new IP and a new Google session, and if the normal endpoint stays blocked it falls back to Google's embeddable widgets and then to a real browser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;git+https://github.com/Egrarobo/pytrends-alternative.git
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;APIFY_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your-token"&lt;/span&gt;   &lt;span class="c"&gt;# free account at apify.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your code changes by one import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;gtrends_api&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;TrendReq&lt;/span&gt;   &lt;span class="c1"&gt;# was: from pytrends.request import TrendReq
&lt;/span&gt;
&lt;span class="n"&gt;pytrends&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TrendReq&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;pytrends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build_payload&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tea&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;timeframe&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;today 12-m&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;geo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;US&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pytrends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;interest_over_time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;          &lt;span class="c1"&gt;# same DataFrame shape as pytrends
&lt;/span&gt;&lt;span class="n"&gt;regions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pytrends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;interest_by_region&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolution&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REGION&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;related&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pytrends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;related_queries&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;        &lt;span class="c1"&gt;# {"coffee": {"top": df, "rising": df}, ...}
&lt;/span&gt;&lt;span class="n"&gt;trending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pytrends&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trending_searches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pn&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;united_states&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;p&gt;It is not free, because proxies and browsers are not free: about &lt;strong&gt;$4 per 1,000 keywords&lt;/strong&gt;, and you only pay for keywords where all the data came back. Apify's free plan includes a small monthly credit, which is enough to test it and to run small weekly reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you have more than 5 keywords
&lt;/h2&gt;

&lt;p&gt;Google compares at most 5 terms at a time, each batch scaled to its own maximum, so values from different batches are not comparable. The underlying &lt;a href="https://apify.com/egra_van/google-trends-reliable" rel="noopener noreferrer"&gt;Google Trends Scraper&lt;/a&gt; solves this with an &lt;strong&gt;anchor term&lt;/strong&gt;: it puts one stable keyword in every batch and rescales all batches onto one 0–100 scale. That is useful for ranking a long keyword list, for example 200 product names.&lt;/p&gt;

&lt;h2&gt;
  
  
  No-code option
&lt;/h2&gt;

&lt;p&gt;If you don't need Python, the same scraper runs in the browser, on a schedule, and exports to Excel or Google Sheets, or it can be called from Make, Zapier or n8n.&lt;/p&gt;




&lt;p&gt;The library is MIT-licensed. Issues and pull requests are welcome: &lt;a href="https://github.com/Egrarobo/pytrends-alternative" rel="noopener noreferrer"&gt;github.com/Egrarobo/pytrends-alternative&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was written with the help of an AI assistant; the code was tested before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>seo</category>
      <category>webscraping</category>
    </item>
  </channel>
</rss>
