GeneralMills / pytrends

Pseudo API for Google Trends
Other
3.25k stars 815 forks source link

'TrendReq' object has no attribute 'trend' #114

Closed MAydogdu closed 7 years ago

MAydogdu commented 7 years ago

Hi all,

I have been using pytrends successfully until a few days ago. I now run the following code to get an error:

import pytrends from pytrends.request import TrendReq google_username = "" google_password = "" pytrend = TrendReq(google_username, google_password, custom_useragent='My Pytrends Script') trend_payload = {'q': 'new', 'geo': 'US', 'date': '01/2004 154m'} df = pytrend.trend(trend_payload, return_type='dataframe') print(df)

'TrendReq' object has no attribute 'trend'

Anyone having similar issues? Thanks much!

dreyco676 commented 7 years ago

Did you update pytrends? The example seems to be from an old version.

On Tue, Feb 21, 2017 at 10:34 AM, Murat Aydogdu notifications@github.com wrote:

Hi all,

I have been using pytrends successfully until a few days ago. I now run the following code to get an error:

import pytrends from pytrends.request import TrendReq google_username = "" google_password = "" pytrend = TrendReq(google_username, google_password, custom_useragent='My Pytrends Script') trend_payload = {'q': 'new', 'geo': 'US', 'date': '01/2004 154m'} df = pytrend.trend(trend_payload, return_type='dataframe') print(df)

'TrendReq' object has no attribute 'trend'

Anyone having similar issues? Thanks much!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GeneralMills/pytrends/issues/114, or mute the thread https://github.com/notifications/unsubscribe-auth/AGxCB0fxYh2d0v0KjlYTgDmGSadY4ysFks5rexIbgaJpZM4MHjUl .

MAydogdu commented 7 years ago

Thanks for the reponse!

Yes, I did update pytrends. I just did pip install pytrends --upgrade one more time and it looks like all related packages are up to date.

A few days ago I did a general update of all python packages using conda and homebrew. I think that maybe this is due to a package that got updated, but I cannot be sure.

turnerniles commented 7 years ago

@dreyco676 Could this issue and the recently opened #113 be related to https://github.com/pat310/google-trends-api/issues/50

It seems like the google trends API url changed.

I think you will need to change the url, https://www.google.com/trends/api/explore to https://trends.google.com/trends/api/explore in all places.

dreyco676 commented 7 years ago

@MAydogdu can you look at the new example and see if that works, the API changed.

dreyco676 commented 7 years ago
from pytrends.request import TrendReq

# enter your own credentials
google_username = "xxx@gmail.com"
google_password = "xxx"
path = ""

# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq(google_username, google_password, custom_useragent='My Pytrends Script')

# Create payload and capture API tokens. Only needed for interest_over_time(), interest_by_region() & related_queries()
pytrend.build_payload(kw_list=['pizza', 'bagel'])

# Interest Over Time
interest_over_time_df = pytrend.interest_over_time()

# Interest by Region
interest_by_region_df = pytrend.interest_by_region()

# Related Queries, returns a dictionary of dataframes
related_queries_dict = pytrend.related_queries()

# Get Google Hot Trends data
trending_searches_df = pytrend.trending_searches()

# Get Google Top Charts
top_charts_df = pytrend.top_charts(cid='actors', date=201611)

# Get Google Keyword Suggestions
suggestions_dict = pytrend.suggestions(keyword='pizza')
MAydogdu commented 7 years ago

Thanks for your help. I have tried this again:

trend_payload = {'q': 'new', 'geo': 'US', 'date': '01/2004 154m'} df = pytrend.trend(trend_payload, return_type='dataframe') print(df)

I get

AttributeError: 'TrendReq' object has no attribute 'trend'

But some things seem to be working, for instance:

Create payload and capture API tokens. Only needed for interest_over_time(), interest_by_region() & related_queries()

pytrend.build_payload(kw_list=['pizza', 'bagel'])

Interest Over Time

interest_over_time_df = pytrend.interest_over_time() print(interest_over_time_df)

works fine.

Is there anything different with pytrend.trend attribute?

dreyco676 commented 7 years ago

Yes, there was a major update due to Google changing their backend. The documentation should answer your questions, let me know if you need additional clarification.

MAydogdu commented 7 years ago

Thanks for your response again. I am trying to write the code that'd give me the equivalent of

trend_payload = {'q': 'new', 'geo': 'US', 'date': '01/2004 154m'} df = pytrend.trend(trend_payload, return_type='dataframe')

using the updated pytrend. It looks like I'd have to do something like

pytrend.build_payload(kw_list='new' , geo = 'US' , timeframe = '01/2004 154-m') interest_over_time_df = pytrend.interest_over_time()

but I get 'ValueError: No JSON object could be decoded'

I have been downloading trends for a few thousand words and I am maybe two thirds done. It's be nice to get the rest of the words in a manner similar to the ones I have already downloaded. Any thoughts on how to correctly enter the timeframe? Thanks again!

dreyco676 commented 7 years ago

Try using this for a timeframe.

'2004-01-01 2017-02-01'

MAydogdu commented 7 years ago

This works great except I get weekly scores now. Can I specify monthly? Thanks again!