Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用python向Gmail API发送批处理请求?_Python_Google Api_Gmail_Gmail Api_Google Api Python Client - Fatal编程技术网

如何用python向Gmail API发送批处理请求?

如何用python向Gmail API发送批处理请求?,python,google-api,gmail,gmail-api,google-api-python-client,Python,Google Api,Gmail,Gmail Api,Google Api Python Client,我目前正在编写一个使用Gmail API的小python脚本。我正在尝试向gmail服务器发送批处理请求。由于gmail发送批处理请求的原生方法在2020年8月被贬低,我不得不自己构建一个。它必须采用“多部分/混合”的形式 根据文档,它必须看起来像这样(): 我尝试使用python请求库,但它似乎只支持“multipart/form”形式的请求。但我不确定 # A list with all the message-id's. messages = tqdm(gmail.list_messag

我目前正在编写一个使用Gmail API的小python脚本。我正在尝试向gmail服务器发送批处理请求。由于gmail发送批处理请求的原生方法在2020年8月被贬低,我不得不自己构建一个。它必须采用“多部分/混合”的形式

根据文档,它必须看起来像这样():

我尝试使用python请求库,但它似乎只支持“multipart/form”形式的请求。但我不确定

# A list with all the message-id's.
messages = tqdm(gmail.list_messages('me'))

gmailUrl = "https://gmail.googleapis.com/batch/gmail/v1"

request_header = {"Host": "www.googleapis.com", "Content-Type": "multipart/mixed", "boundary"="bound"}

request_body = ""

# I want to bundle 80 GET requests in one batch.
# I don't know how to proceed from here.
for n in range(0,80):


response = req.post(url=gmailUrl, auth=creds, headers=request_header, files=request_body)

print(response)
所以我的问题很简单:

如何使用python以“多部分/混合”形式向Gmail API发送http请求


提前谢谢

为什么要批处理请求?你知道你所要做的就是为自己节省一些HTTP流量,对吗?作为对尝试让批处理与谷歌API一起工作的挫折的交换,我正在与其他函数的API一起工作。但是发送这么多http请求(并再次接收它们)似乎花费的时间比需要的时间更长。我希望您运气好,这可能会有所帮助,但可能不会,因为批处理端点在发布此答案后发生了更改,但这是我唯一能找到的。这是一个免费的API,你只需付费即可获得。仅供参考,批处理不会加快任何速度或提高您的配额,因为它需要处理的请求数量相同。谢谢。我现在搜索了几个小时(发现了很多你评论过的帖子)。基本上,问题似乎只是我不知道如何正确发送请求。我使用谷歌API已经十年了,大约七年前我放弃了批处理。我发现它不值得尝试让它工作时所带来的挫折。我不是Python开发人员,所以我帮不了多少忙。首先尝试使用get请求进行批处理,然后再尝试发送邮件。我确实认为你可能会有问题,因为它可能看起来像是向谷歌发送垃圾邮件。确保你正在使用一个虚拟帐户进行测试,以防你被锁定。