我最近一直在使用 Python 的 pytrends 来处理 Google 趋势。我在随机请求期间遇到以下错误:
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 趋势配额限制有关。例如,this讨论上述问题。
但就我而言,即使在很长一段时间后的第一次请求中,我也遇到过这种情况,并且我继续多次收到它,直到我最终得到正确的答复。大约 5 个请求中就会出现一次成功响应,而其余的都是错误的。
注意:需要注意的是,我今天才遇到这个问题,尽管我在过去两天使用 Google 趋势时从未遇到过这个问题。
相关代码片段如下:
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
是什么原因导致此问题以及我该如何处理?
最佳答案
该术语称为 load shedding :这意味着谷歌服务器足够聪明,可以识别出它们何时收到无法处理的负载(太多请求),因此它们开始将其中一些“放在地板上”(意思是,用您看到的错误进行响应,而不是正确处理它)。
从客户端(您的代码)处理它的方法是使用 exponential backoff 实现重试机制。在重试之间休眠。
您可以在 their docs 中查看有关其 SLA 的更多信息。 .
关于python - Google 趋势错误 : Sorry, 我们的系统现在有点压力,需要深呼吸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41991213/