为什么google-api-python-client的发现导致超时?

时间:2017-08-23 05:27:00

标签: python http google-api-python-client httplib2

在我的网络应用中使用discovery.build()(版本1.6.2)中的google-api-python-client会导致超时。运行以下代码

import httplib2
from apiclient import discovery

http = httplib2.Http()
discovery.build('classroom', 'v1', http=http)

大约需要80秒(!) - 我的网络服务器超时为30秒。

我相信Google API客户端的调用是:

http = httplib2.Http()
response, content = http.request(
    'https://www.googleapis.com/discovery/v1/apis/classroom/v1/rest',
    'GET',
    body=None,
    headers={},
)

也需要大约80秒,并检索大约141 KiB的数据。

而等效curl

curl -H 'accept-encoding: gzip, deflate' \
     'https://www.googleapis.com/discovery/v1/apis/classroom/v1/rest'

需要0.5秒。

为什么需要这么长时间?我能做些什么来阻止它 - 有更快的方法吗?

0 个答案:

没有答案