GeneralMills / pytrends

Pseudo API for Google Trends
Other
3.28k stars 821 forks source link

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

Open aspiringguru opened 4 years ago

aspiringguru commented 4 years ago

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

TarmacD commented 4 years ago

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

William-Lake commented 4 years ago

You just saved me troubleshooting time- thank you!

lizw-au commented 4 years ago

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

hehesangsj commented 4 years ago

Thanks! You solved my problem

nicolaspro1234 commented 4 years ago

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

oeyvindds commented 3 years ago

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'