0
votes

I run the following code to get an error:

from pytrends.request import TrendReq
google_username = ''
google_password = ''
pytrend = TrendReq(google_username, google_password, custom_useragent='My Pytrends Script')
pytrend.build_payload(kw_list=['apple', 'sony'], timeframe = 'now 7-d')

pytrend.trending_searches()

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

pytrend.top_charts(date='201611', cid='apple', geo='US', cat='')

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Anyone having similar issues? Thanks a lot!

1

1 Answers

0
votes

Looks like pytrends in pip is out of date. Try to take pytrends from git

pip install git+https://github.com/GeneralMills/pytrends@master --upgrade

UPDATE 1:

At least they use different URL for trending searches. Source from pip (pytrends/request.py):

def trending_searches(self):
    """Request data from Google's Trending Searches section and return a dataframe"""

    # make the request
    req_url = "https://www.google.com/trends/hottrends/hotItems"

Source from master branch:

TRENDING_SEARCHES_URL = 'https://trends.google.com/trends/hottrends/hotItems'

# some code 

def trending_searches(self):
    """Request data from Google's Trending Searches section and return a dataframe"""

    # make the request
    forms = {'ajax': 1, 'pn': 'p1', 'htd': '', 'htv': 'l'}
    req_json = self._get_data(
        url=TrendReq.TRENDING_SEARCHES_URL,
        method=TrendReq.POST_METHOD,
        data=forms,
    )['trendsByDateList']
    result_df = pd.DataFrame()