Python 为什么这种mime类型对于创建Google文档无效?

Python 为什么这种mime类型对于创建Google文档无效?,python,google-api,google-drive-api,Python,Google Api,Google Drive Api,我已经为代码创建了一个“包装器”类。除非我改变mime类型,否则它在我的课堂上很好用。在他们的代码中,他们创建了一个纯文本文档,但我正试图用我的代码创建一个Google文档文件。当我尝试运行此代码时,我收到一个HttpError 400,指出我的mime类型无效。我到底做错了什么 这是我的密码: import pprint import httplib2 import googleapiclient.discovery import googleapiclient.http import goo

我已经为代码创建了一个“包装器”类。除非我改变mime类型,否则它在我的课堂上很好用。在他们的代码中,他们创建了一个纯文本文档,但我正试图用我的代码创建一个Google文档文件。当我尝试运行此代码时,我收到一个HttpError 400,指出我的mime类型无效。我到底做错了什么

这是我的密码:

import pprint
import httplib2
import googleapiclient.discovery
import googleapiclient.http
import googleapiclient.errors
import oauth2client.client


class DriveClient():
    def __init__(self):
        self.oauth2_scope = 'https://www.googleapis.com/auth/drive'
        self.client_secrets = 'client_secrets.json'
        self.mimetype = 'application/vnd.google-apps.document'
        self.flow = self.set_flow()
        self.drive_service = self.authorize_url()

    def set_flow(self):
        flow = oauth2client.client.flow_from_clientsecrets(self.client_secrets,
                                                           self.oauth2_scope)
        flow.redirect_uri = oauth2client.client.OOB_CALLBACK_URN
        return flow

    def authorize_url(self):
        authorize_url = self.flow.step1_get_authorize_url()
        print('Go to the following link in your browser: ' + authorize_url)
        code = input('Enter verification code: ').strip()
        credentials = self.flow.step2_exchange(code)

        http = httplib2.Http()
        credentials.authorize(http)
        drive_service = googleapiclient.discovery.build('drive', 'v2',
                                                        http=http)
        return drive_service

    def push_file(self, file_src, title, description=''):
        media_body = googleapiclient.http.MediaFileUpload(
                file_src, mimetype=self.mimetype, resumable=True)
        body = {
            'title': title,
            'description': description
        }
        try:
            new_file = self.drive_service.files().insert(body=body,
                                                     media_body=media_body
                                                     ).execute()
            pprint.pprint(new_file)
        except googleapiclient.errors.HttpError as error:
            print('An error occured: %s' % error)


if __name__ == '__main__':
    d = DriveClient()
    d.push_file('document.txt', 'mTitle', 'mDescription')

尝试将mime类型设置为源文档的类型,例如
application/msword
application/vnd.oasis.opendocument.text
,等等。Google需要知道传入文档的格式,然后它将选择创建哪种类型的google文档。

这就像mime类型
text/plain
一样有效。它创建了一个MS Word文档,但我特别想创建一个Google文档。