How to set timeout for urlfetch in Google App Engine?

前端 未结 4 1478
灰色年华
灰色年华 2020-12-10 11:56

I\'m trying to have Django (on top of GAE) fetch data from another web service. I\'m often hit with error like this:

ApplicationError: 2 timed out Req

4条回答
  •  时光说笑
    2020-12-10 12:06

    You can set it using the deadline argument of the fetch function. From the docs:

    The deadline can be up to a maximum of 60 seconds for request handlers and 10 minutes for tasks queue and cron job handlers. If deadline is None, the deadline is set to 5 seconds.


    Edit: looks like this has changed now. From here:

    You can set a deadline for a request, the most amount of time the service will wait for a response. By default, the deadline for a fetch is 5 seconds. You can adjust the default deadline for requests using the urlfetch.set_default_fetch_deadline() function.

    And this page lists the default timeout values:

    Currently, there are several errors named DeadlineExceededError for the Python runtime:

    • google.appengine.runtime.DeadlineExceededError: raised if the overall request times out, typically after 60 seconds, or 10 minutes for task queue requests.
    • google.appengine.runtime.apiproxy_errors.DeadlineExceededError: raised if an RPC exceeded its deadline. This is typically 5 seconds, but it is settable for some APIs using the 'deadline' option.
    • google.appengine.api.urlfetch_errors.DeadlineExceededError: raised if the URLFetch times out.

提交回复
热议问题