我最近一直在使用 Python 的 pytrends 与 Google Trends 合作。我在随机请求期间遇到了以下错误:
Response did not parse. See server response for details.
Sorry, our systems are a little stressed out right now and need to take a deep breath. Please try again in a few moments.
经过搜索,我发现这与 Google Trends Quota 限制有关。例如,这讨论了提到的问题。
但就我而言,即使在很长一段时间后的第一次请求中,我也一直在经历这种情况,并且我继续多次得到它,直到我最终得到正确的响应。大约 5 个请求中会出现一次成功响应,而其余的都是错误的。
注意:需要注意的是,我今天才遇到这个问题,尽管我在过去两天使用谷歌趋势时从未遇到过这个问题。
相关代码片段如下:
pytrends = get_pytrends()
payload = {'q': 'chelsea', 'date' : 'now 12-H'}
print(json.dumps(pytrends.trend(payload, return_type='json'), indent=4))
get_pytrends()
def get_pytrends():
try:
google_username = os.environ['GOOGLE_USERNAME']
google_password = os.environ['GOOGLE_SECRET']
except KeyError:
sys.stderr.write("GOOGLE_* environment variables not set\n")
sys.exit(1)
pytrends = TrendReq(google_username, google_password, custom_useragent=None)
return pytrends
是什么导致了这个问题,我应该如何处理?