Google趋势错误:对不起,我们的系统现在压力有点大,需要深呼吸 [英] Google Trends error: Sorry, our systems are a little stressed out right now and need to take a deep breath
问题描述
我最近一直在使用Python的pytrends与Google趋势进行合作.而且我在随机请求期间遇到以下错误:
I have been working with Google Trends recently using Python's pytrends. And I have been experiencing the following error during random requests:
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趋势配额限制有关.例如,此讨论了所提到的问题.
Upon searching I discovered that this was related to the Google Trends Quota limits. For example, this discusses about the mentioned issue.
但是,就我而言,即使是在很长一段时间后的第一次请求中,我也一直遇到这种情况,并且我继续获得了好几次,直到最终得到适当的答复.成功的响应大约在5个请求中发生一次,而其余请求是错误的.
But in my case, I have been experiencing this even during my first request after a long period of time and I continue to get it several times until I finally get a proper response. A successful response occurs once in around 5 requests, whereas the rest are erroneous.
注意:必须注意的是,我直到今天才遇到此问题,尽管最近两天我从未使用过Google趋势.
Note: it has to be noted that I came across this issue only today although I never came across this when I used Google Trends during the last two days.
相关的代码片段如下:
pytrends = get_pytrends()
payload = {'q': 'chelsea', 'date' : 'now 12-H'}
print(json.dumps(pytrends.trend(payload, return_type='json'), indent=4))
get_pytrends()
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
什么原因导致此问题,我应该如何处理?
What causes this issue and how should I handle it?
推荐答案
该术语称为甩负荷:这意味着google服务器足够聪明,可以识别出无法处理的负载(请求过多),因此它们开始将其中一些丢在地板上"(意思是,以您遇到的错误进行响应重新看到,而不是对其进行适当处理).
The term is called load shedding: it means that google servers are smart enough to recognize when they get a load they can't handle (too many requests) so they start dropping some of them "on the floor" (meaning, respond with the error you're seeing, instead of processing it properly).
The way to deal with it from the client-side (your code) is to implement a retry mechanism with an exponential backoff sleep in between retries.
您可以在他们的文档中查看有关其SLA的更多信息.
You can see more about their SLA in their docs.
这篇关于Google趋势错误:对不起,我们的系统现在压力有点大,需要深呼吸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!