Skip to content

Commit

Permalink
Merge pull request #553 from xenova/master
Browse files Browse the repository at this point in the history
Fix 429 errors (Fixes #354, #413, #492, #523, #535, #538) and fix pandas `frame.append` deprecation warning (Fixes #525)
  • Loading branch information
emlazzarin authored Dec 26, 2022
2 parents c6d73de + 18f230d commit 424c2c1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pytrends/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def __init__(self, hl='en-US', tz=360, geo='', timeout=(2, 5), proxies='',
self.related_topics_widget_list = list()
self.related_queries_widget_list = list()

self.headers = {'accept-language': self.hl}
self.headers.update(self.requests_args.pop('headers', {}))

def GetGoogleCookie(self):
"""
Gets google cookie (used for each and every proxy; once on init otherwise)
Expand Down Expand Up @@ -125,7 +128,7 @@ def _get_data(self, url, method=GET_METHOD, trim_chars=0, **kwargs):
method_whitelist=frozenset(['GET', 'POST']))
s.mount('https://', HTTPAdapter(max_retries=retry))

s.headers.update({'accept-language': self.hl})
s.headers.update(self.headers)
if len(self.proxies) > 0:
self.cookies = self.GetGoogleCookie()
s.proxies.update({'https': self.proxies[self.proxy_index]})
Expand Down Expand Up @@ -482,14 +485,11 @@ def today_searches(self, pn='US'):
url=TrendReq.TODAY_SEARCHES_URL,
method=TrendReq.GET_METHOD,
trim_chars=5,
params=forms
params=forms,
**self.requests_args
)['default']['trendingSearchesDays'][0]['trendingSearches']
result_df = pd.DataFrame()
# parse the returned json
sub_df = pd.DataFrame()
for trend in req_json:
sub_df = sub_df.append(trend['title'], ignore_index=True)
result_df = pd.concat([result_df, sub_df])
result_df = pd.DataFrame(trend['title'] for trend in req_json)
return result_df.iloc[:, -1]

def realtime_trending_searches(self, pn='US', cat='all', count =300):
Expand Down

0 comments on commit 424c2c1

Please sign in to comment.