Google 地方 API 错误 502 - 服务器遇到临时错误

Google Places API error 502 - The server encountered a temporary error

我们 运行 一个通过 Google 地点 API 获取位置数据的网站。我们每天有 150,000 次可用搜索,但由于该网站仅上线几周,我们还没有遇到过。我们突然收到 502 错误。控制台中的通知显示:“服务器遇到临时错误,无法完成您的请求。”。这是一个临时错误吗?对我们可以做什么有什么建议吗?该网站已 40 分钟无法使用。

当您在响应中收到 5xx 状态或 UNKNOWN_ERROR 时,您应该实施重试逻辑。 Google 在其网络服务文档中有以下建议:

In rare cases something may go wrong serving your request; you may receive a 4XX or 5XX HTTP response code, or the TCP connection may simply fail somewhere between your client and Google's server. Often it is worthwhile re-trying the request as the followup request may succeed when the original failed. However, it is important not to simply loop repeatedly making requests to Google's servers. This looping behavior can overload the network between your client and Google causing problems for many parties.

A better approach is to retry with increasing delays between attempts. Usually the delay is increased by a multiplicative factor with each attempt, an approach known as Exponential Backoff.

https://developers.google.com/maps/documentation/directions/web-service-best-practices#exponential-backoff

但是,如果使用指数退避重试逻辑没有帮助并且错误持续很长时间,您应该在 Google issue tracker

中提交错误

希望这能解决您的疑问!

更新

昨天(2017 年 11 月 6 日)Google 端出现问题,您可以参考以下说明问题的错误:

https://issuetracker.google.com/issues/68938173