Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 429 errors (Fixes #354, #413, #492, #523, #535, #538) and fix pandas frame.append deprecation warning (Fixes #525) #553

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pytrends/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -124,7 +127,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 @@ -432,14 +435,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