Lucas Ian
Lucas Ian

Reputation: 25

Pytrends - ResponseError: The request failed: Google returned a response with code 400

I am trying to search trends on "coronavirus" word, and for the code:

import pandas as pd                        
from pytrends.request import TrendReq

pytrend = TrendReq()


pytrend.build_payload(kw_list=['sintomas covid'],timeframe='2020-02-26 today', geo='BR')
 
# Interest Over Time
interest_over_time_df = pytrend.interest_over_time()

I keep getting:

ResponseError: The request failed: Google returned a response with code 400.

Already tried this.

Upvotes: 2

Views: 3579

Answers (1)

Tejas
Tejas

Reputation: 401

It is because of timeframe parameter, it should be one of the following format

  • Specific dates, 'YYYY-MM-DD YYYY-MM-DD' example '2016-12-14 2017-01-25'
  • Specific datetimes, 'YYYY-MM-DDTHH YYYY-MM-DDTHH' example '2017-02-06T10 2017-02-12T07'

You can use this code, for your use case

import pandas as pd      
from datetime import date
from pytrends.request import TrendReq

pytrend = TrendReq()


pytrend.build_payload(kw_list=['sintomas covid'],timeframe=f'2020-02-26 {date.today()}', geo='BR')
 
# Interest Over Time
pytrend.interest_over_time()

Upvotes: 3

Related Questions