python脚本中的刷新令牌似乎不适用于Google Drive

python脚本中的刷新令牌似乎不适用于Google Drive,python,refresh,google-oauth,Python,Refresh,Google Oauth,我正在使用下面的Python脚本将文件上载到Google驱动器。当需要用户交互以获取授权密钥时,它会在第一次上传fine。但是,当我再次尝试上载文件时,会出现以下错误: raise HttpError(resp,content,uri=self.uri) apiclient.errors.HttpError:https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&alt=json 返回“无效上载请求”> 这到底是

我正在使用下面的Python脚本将文件上载到Google驱动器。当需要用户交互以获取授权密钥时,它会在第一次上传fine。但是,当我再次尝试上载文件时,会出现以下错误:

raise HttpError(resp,content,uri=self.uri) apiclient.errors.HttpError:https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&alt=json 返回“无效上载请求”>

这到底是什么意思? 我猜刷新令牌并不是我想要它做的

#!/usr/bin/python

import httplib2
import pprint

from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.file import Storage

CLIENT_ID = '*************************************************************************'
CLIENT_SECRET = '*****************************'

OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive'

REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

FILENAME = '/home/student/Desktop/TraceRoute.kml'

CRED_FILENAME = 'credentials'

### For storing token
storage = Storage(CRED_FILENAME)

if not storage.get():
    # Run through the OAuth flow and retrieve authorization code
    flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
    authorize_url = flow.step1_get_authorize_url()
    print 'Go to the following link in your browser: ' + authorize_url
    code = raw_input('Enter verification code: ').strip()
    credentials = flow.step2_exchange(code)

    ### Storing access token and a refresh token in CRED_FILENAME
    storage.put(credentials)
else:
    ### Getting access_token,expires_in,token_type,Refresh_toke info from CRED_FILENAME                    to 'credentials'
credentials = storage.get()

http = httplib2.Http()
http = credentials.authorize(http)

drive_service = build('drive', 'v2', http=http)

# Insert a file
media_body = MediaFileUpload(FILENAME, mimetype='text/plain', resumable=True)
body = {
    'title': 'My document',
    'description': 'A test document',
    'mimeType': 'text/plain'
}

file = drive_service.files().insert(body=body, media_body=media_body).execute()
pprint.pprint(file)

由于我使用的是Python3,而google api客户端只支持Python2,所以我使用了这个小库,经过几次修改后,它可以很好地用于我的应用程序。将失败的http请求和响应粘贴到问题中