pytrends icon indicating copy to clipboard operation
pytrends copied to clipboard

valid values for values for timeframe in .build_payload (code 400 error)

Open aspiringguru opened this issue 4 years ago • 6 comments

I had trouble debugging errors, typically code 400, turns out the service only accepts inputs replicating the web form (obvious really).

I saw this a lot, thought it was an api timeout. pytrends.exceptions.ResponseError: The request failed: Google returned a response with code 400.

after some trial and error I found these values work by replicating the url created by the form.

'now 1-H', 'now 4-H', 'now 1-d', 'now 7-d', 'today 1-m', 'today 3-m', 'today 12-m', 'today 5-y', 'all'

ie https://trends.google.com/trends/explore?date=today%201-m&geo=US&q=tesla

if there is sufficient interest I can submit a pull request to one of these files.

https://github.com/GeneralMills/pytrends/blob/master/README.md or https://github.com/GeneralMills/pytrends/blob/master/examples/example.py

aspiringguru avatar Apr 03 '20 04:04 aspiringguru

Thank you, helped me a lot! I definetly suggest to submit a pull request!

TarmacD avatar Apr 03 '20 17:04 TarmacD

You just saved me troubleshooting time- thank you!

William-Lake avatar Apr 09 '20 12:04 William-Lake

Thankyou - I'm working on this now and have been running through trial and error also.

lizw-au avatar May 07 '20 00:05 lizw-au

Thanks! You solved my problem

hehesangsj avatar May 08 '20 07:05 hehesangsj

Thank you, I am not native English speaker. What do you mean exactly by

I found these values work by replicating the url created by the form

Thank you

nicolaspro1234 avatar May 27 '20 16:05 nicolaspro1234

Thank you, I am not native English speaker. What do you mean exactly by

I found these values work by replicating the url created by the form

Thank you

He read the urls that are generated, and found the keywords in the urls.

For example, in this url: https://trends.google.com/trends/explore?date=today%201-m&geo=US&q=tesla

you can see 'today 1-m'

oeyvindds avatar Nov 21 '20 11:11 oeyvindds