I have tried many things, but still get the 400 error after hours, any assistance appreciated.
The Goal:
My goal is to select the top X current trending search, returning the topic. Ex-Get the 3rd(2) option from the realtime_trending_searches
method, returning it via string at the end, such as “Kanye west”. This works for daily trends.
I have tried:
Creating a payload; Using keywords(empty list); Changing timezone, country, gprop; Multiple small changes to code to print/see if data is properly displayed/called.
My exact Error:
pytrends.exceptions.ResponseError: The request failed: Google returned a response with code 400
Unsure of next steps, code below:
from pytrends.request import TrendReq
def get_trends_google(x):
trends = TrendReq()
trends.build_payload(kw_list='')
trending_searches = trends.realtime_trending_searches(pn="united_states")
#trending_searches[0][0] will give the first result. [0][1] will give second, etc.
print(trending_searches)
return trending_searches[0][x]
where X is an integer to simply call from the list given.
I copied this code from myself, but instead of realtime_trending_searches
, I just used trending_searches
. Using the latter, it works just fine, getting (for example right now) Boston Bruins. I had figured it would use the same process, but I was wrong.
The code is in python, I have other code but it is not using pytrends. The only outside-the-function code that effects this function is x, which is simply an int.
Any help or ideas appreciated!