I'm teaching my class how to do data analysis in Python. We are attempting to use Pytrends to gather datasets for the students to analyze.
The first day of the lesson, pytrends worked great. However, we are now getting frequent, intermittent Google 429 (too many requests) errors.
We've followed some online suggestions to fix the error including setting retries=3 (or greater), clearing cache and cookies, and modifying the requests.py file in the pytrends library. However, the 429 error persists.
Questions:
Students are using this basic code with the keyword list containing items they are interested in:
pytrend = TrendReq(retries=3)
kw = ["cookies", "pie", "cake"]
pytrend.build_payload(kw)
try:
df = pytrend.interest_over_time()
except Exception:
print("Error")
I'm teaching my class how to do data analysis in Python. We are attempting to use Pytrends to gather datasets for the students to analyze.
The first day of the lesson, pytrends worked great. However, we are now getting frequent, intermittent Google 429 (too many requests) errors.
We've followed some online suggestions to fix the error including setting retries=3 (or greater), clearing cache and cookies, and modifying the requests.py file in the pytrends library. However, the 429 error persists.
Questions:
Students are using this basic code with the keyword list containing items they are interested in:
pytrend = TrendReq(retries=3)
kw = ["cookies", "pie", "cake"]
pytrend.build_payload(kw)
try:
df = pytrend.interest_over_time()
except Exception:
print("Error")
This is a common issue that has also been reported by individual users and it seems to be as a result of actions taken by Google against spam bots as suggested in this issue.
Do note that pytrends is an Unofficial API for Google Trends and the error code 429 indicates that your requests to the Google Trends API have exceeded the rate limit.
Some temporary fix that has been suggested includes; introducing a delay between requests, reducing the number of requests, using batch processing or simply using proxies.
See if any of these closed issues helps.