我有一个任务处理程序正在向 Google Calendar API 发出批处理请求。 5 秒后,请求因 DeadlineExceededError 失败:API 调用 urlfetch.Fetch() 响应时间过长而被取消。 我已更改 urlfetch.set_default_fetch_deadline(60)根据建议,在我发出批量请求的地方附近 here但这似乎没有什么不同:截止日期似乎仍然是 5 秒。
我正在使用位于 oauth2client 和 httplib2 之上的 Python Google API 客户端库。但我的理解是,GAE 拦截了使用 urlfetch.Fetch 的底层调用。这也是堆栈跟踪显示的内容。
您能看出 urlfetch.set_default_fetch_deadline 似乎不起作用的任何原因吗?
编辑:
这是用于构建批处理请求的代码:
# note `http` is a oauth2client authorized http client
cal = apiclient.discovery.build('calendar','v3',http=http)
req = cal.new_batch_http_request(callback=_callback)
for event in events: # anything larger than ~5 events in batch takes >5 secs
req.add(
cal.events().patch(calendarId=calid, eventId=event["id"], body=self._value)
)
urlfetch.set_default_fetch_deadline(60) # has no effect
req.execute()
请您参考如下方法:
所以,urlfetch.set_default_fetch_deadline() 最终对我有用。问题是我的底层 http 客户端 (oauth2client/httplib2) 基本上存储在一个全局的。一旦我在任务处理程序线程中创建它,set_default_fetch_deadline 就起作用了。
