G-Suite / Gmail API-无法创建带有附件的草稿-Python3

时间:2019-01-02 12:27:14

标签: python-3.x urllib gmail-api gsuite

以下是我的代码。 我正在尝试创建带有附件的草稿。

raw_data包含SubjectToFromCCAttachment

_url = "https://www.googleapis.com/upload/gmail/v1/users/me/drafts"
message = {"message": {"raw": raw_data}}
body = json.dumps(message).encode('utf8')
_file_size = len(body)

request = urllib.request.Request(_url)

request.add_header('Content-type', 'message/rfc822')
request.add_header('Accept', '*/*')
request.add_header('Authorization', 'Bearer ' + session['access_token'])
request.add_header('Content-length', _file_size)
request.data = body

变量body的值:

b'{"message": {"raw": "Q29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PSI9PT09PT09PT09PT09PT0wNzQ4NzI5MDk3PT0iCk1JTUUtVmVyc2lvbjogMS4wCnRvOiB0ZXN0QGFiYy5jb20KY2M6IHRlc3QxQGFiYy5jb20KZnJvbTogdGVzdDJAYWJjLmNvbQpzdWJqZWN0OiB0ZXN0IG1haWwKCi0tPT09PT09PT09PT09PT09MDc0ODcyOTA5Nz09CkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD0idXMtYXNjaWkiCk1JTUUtVmVyc2lvbjogMS4wCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IDdiaXQKCm1lc3NhZ2VfdGV4dAotLT09PT09PT09PT09PT09PTA3NDg3MjkwOTc9PQpDb250ZW50LVR5cGU6IGltYWdlL3BuZwpNSU1FLVZlcnNpb246IDEuMApDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiBiYXNlNjQKQ29udGVudC1EaXNwb3NpdGlvbjogYXR0YWNobWVudDsgZmlsZW5hbWU9Im1pbnVzLnBuZyIKCmlWQk9SdzBLR2dvQUFBQU5TVWhFVWdBQUFBa0FBQUFKQ0FNQUFBRFhUL1lpQUFBQURGQk1WRVdxcXFyMDlQVC8vLzhBQUFEYUwrOW0KQUFBQUhFbEVRVlFJbVdOZ1FBQkdDQUN4bUVBQWpjVU1BamhsNFhwaEFBQU9QUUJRcms3bTl3QUFBQUJKUlU1RXJrSmdnZz09CgotLT09PT09PT09PT09PT09PTA3NDg3MjkwOTc9PS0tCg=="}}'

当我复制上面的raw值并在Google API Explorer上进行测试时,我可以使用有效的SubjectToFrom创建草稿, CC和一个Attachment

但是当我尝试运行上述代码时,将创建一个空草稿。 (没有SubjectToFromCCAttachment)。 -这是意外行为

0 个答案:

没有答案