Google App Engine + Cloud Endpoints + Google Translate API = 502 Bad Gateway

时间:2017-09-11 13:53:34

标签: google-app-engine google-cloud-endpoints google-translate

我使用Cloud Endpoints创建了一个简单的API,它使用Google Translate API进行一些翻译,将它们缓存在Datastore中并将结果列表返回给Client。 问题是,每次拨打电话时,使用Google Translate API都会收到502 Bad Gateway错误。 我已经从云控制台调试我的终端并且响应已成功创建,因此在将结果发送回客户端时必须抛出502。另一个奇怪的事情是我在云控制台中的任何日志记录工具上都看不到502.

我试图将地区从欧洲西部改为我们中心,但到目前为止还没有运气。 有没有人有任何想法,这里可能有什么问题?

我对GAE的评价:

runtime: java7
env: standard
threadsafe: true
instance_class: B2
inbound_services:
  - warmup
handlers:
  - url: '(/.*/)'
    application_readable: false
    static_files: "__static__\\1index.html"
    require_matching_file: true
    upload: __NOT_USED__
  - url: (/)
    application_readable: false
    static_files: "__static__\\1index.html"
    require_matching_file: true
    upload: __NOT_USED__
  - url: '(/.*)'
    application_readable: false
    static_files: "__static__\\1"
    require_matching_file: true
    upload: __NOT_USED__
  - url: /
    script: unused
  - url: '/.*/'
    script: unused
  - url: '/_ah/.*'
    script: unused
basic_scaling:
  idle_timeout: 900s
  max_instances: 2

当更改GAE的配置并删除基本缩放时,我会从Google翻译出现以下错误:

com.google.cloud.translate.TranslateException: com.google.apphosting.api.ApiProxy$CancelledException: The API call urlfetch.Fetch() was cancelled because the overall HTTP request deadline was reached.
at io.stringx.repository.DatastoreTranslationRepository.translate (DatastoreTranslationRepository.java:53)

1 个答案:

答案 0 :(得分:0)

事实证明,Google Cloud Endpoints有60秒的截止时间限制,因此我不得不以块的形式提出请求: https://cloud.google.com/appengine/articles/deadlineexceedederrors#UrlFetch_Delays