Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using the very simple code to find the data of the keyword by region. But everytime i ran it, it gives me 429 error, prompting that too many requests have been made but infact the request was made very first time and never before. The error i am getting is mentioned below.

raise exceptions.TooManyRequestsError.from_response(response) pytrends.exceptions.TooManyRequestsError: The request failed: Google returned a response with code 429

Here is the code, i am running.

import pandas as pd                        
from pytrends.request import TrendReq
pytrend = TrendReq()
kw_list = ["Blockchain"]
pytrend.build_payload(kw_list, cat=0, timeframe='today 12-m', geo='', gprop='')
# Interest by Region
df = pytrend.interest_by_region()
df.head(10)

Ok, tprogrammer, I think I might have found an answer for you, though I got it from this current github thread: Exception occurred: The request failed: Google returned a response with code 429

///Edit(21.03.23): There is a much more concise solution from user "jesvinc" there that lifts the request limits all around to the point it had been before. Apparently it had to do with the GetGoogleCookie method, which needs a little change. If you go into your python module folder (mine was at User\AppData\Roaming\Python\Python39\site-packages), inside pytrends you will find the file request.py. Open it and change the 'get' to 'post' in line 88 like this:

return dict(filter(lambda i: i[0] == 'NID', requests.get(
return dict(filter(lambda i: i[0] == 'NID', requests.post(

After this change, even the occasional remaining problems also disappeared, and it started to work with VPN again as well. This fix will most likely be in some form included in the next pytrends update, but until then, this works fine.

Nope, not working for me, giving me the below error of max retries. equests.exceptions.RetryError: HTTPSConnectionPool(host='trends.google.com', port=443): Max retries exceeded with url: /trends/api/explore?hl=en-US&tz=360&req=%7B%22comparisonItem%22%3A+%5B%7B%22keyword%22%3A+%22Blockchain%22%2C+%22time%22%3A+%22today+12-m%22%2C+%22geo%22%3A+%22%22%7D%5D%2C+%22category%22%3A+0%2C+%22property%22%3A+%22%22%7D (Caused by ResponseError('too many 429 error responses')) – Hubaib Mar 19 at 11:55 I edited the post since I read up and tested an even better solution. I think it is very likely to solve it for you as well this time. – RiiNagaja Mar 21 at 9:51

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.