Pytrends Not working in 2024 using in Python

356 Views Asked by At

Currently I´m working in a project involving use of pytrends for extract data from google trends. Last month it worked fine but now It gets all times I tried the same error.

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

The code for testing this is following one:

from pytrends.request import TrendReq import pandas as pd

# import plotly.express as px
import time
import json

# Create pytrends object
pytrends = TrendReq(hl='de-DE', tz=360) # 'De' means consider Germany as the search area 
# Set your keyword and time frame
keyword = ['Analytics'] # for example we give 'Data Science' as the search term 
timeframe = 'today 5-y'  # Time frame: last year

# Build the payload for the keyword
pytrends.build_payload(kw_list=keyword,
                       cat=0, # Category 
                       timeframe=timeframe,
                       geo='CR', # Geographic location, in this case 'Deutschland'
                       gprop='') # Google Search Property

interest_over_time_df = pytrends.interest_over_time()

I have tried different options I found.

  1. Use Google trends while executing code
  2. Change request.py file from library folder: return dict(filter(lambda i: i[0] == 'NID', requests.get( by return dict(filter(lambda i: i[0] == 'NID', requests.post(
  3. Set specified parameters like shown: pytrends = TrendReq(hl='en-US', tz=360, timeout=(10,25), proxies=['https://34.203.233.13:80',], retries=2, backoff_factor=0.1, requests_args={'verify':False})

Any of these solutions works now :c

0

There are 0 best solutions below