批处理请求在批处理在Python中执行之前向Google API发出调用?

批处理请求在批处理在Python中执行之前向Google API发出调用?,api,google-api,batch-processing,google-admin-sdk,Api,Google Api,Batch Processing,Google Admin Sdk,我正在通过AdminSDK向Google API发送一个大批量请求,该请求将根据我们内部服务器中的组(重新调整脚本)向某些组添加成员。我使用的是Python,要访问Google API,我使用的是[apiclient库][1]。创建服务和批处理对象时,服务对象的创建会请求一个URL batch_count = 0 batch = BatchHttpRequest() service = build('admin', 'directory_v1') 日志 这是有意义的,因为HTTP调用返回的JS

我正在通过AdminSDK向Google API发送一个大批量请求,该请求将根据我们内部服务器中的组(重新调整脚本)向某些组添加成员。我使用的是Python,要访问Google API,我使用的是[apiclient库][1]。创建服务和批处理对象时,服务对象的创建会请求一个URL

batch_count = 0
batch = BatchHttpRequest()
service = build('admin', 'directory_v1')
日志

这是有意义的,因为HTTP调用返回的JSON对象用于构建服务对象

现在我想在批处理对象中添加多个请求,所以我这样做了

for email in add_user_list:
    if batch_count != 999:
        add_body = dict()
        add_body[u'email'] = email.lower()
        for n in range(0, 5):
            try:
                batch.add(service.members().insert(groupKey=groupkey, body=add_body), callback=batch_callback)
                batch_count += 1
                break
            except HttpError, error:
                logging_message('Quota exceeded, waiting to retry...')
                time.sleep((2 ** n)
                continue
每次遍历最外层的for循环时,它都会记录日志(组地址已编辑)

批处理的目的不是要在批处理请求被所有单个请求填充之前不向API发送任何调用吗?为什么每次都要调用上面显示的API?然后,当我
batch.execute()
执行所有请求时(这是我认为唯一会调用API的区域?)

有一秒钟,我以为调用是构造
.members()
返回的对象,但我尝试了以下更改:

service = build('admin', 'directory_v1').members()

batch.add(service.insert(groupKey=groupkey, body=add_body), callback=batch_callback)
结果还是一样的。这是一个问题的原因,因为它使对API的请求数量增加了一倍,而且我对它的运行规模存在真正的配额问题

INFO:apiclient.discovery:URL being requested:
https://www.googleapis.com/admin/directory/v1/groups/GROUPADDRESS/members?alt=json
service = build('admin', 'directory_v1').members()

batch.add(service.insert(groupKey=groupkey, body=add_body), callback=batch_callback)