您好我尝试使用以下代码将文件上传到Google Cloud 端硬盘
def upload_file(self,file_name,path):
parents = None
if not path == None:
parents = self.create_path(path)
mime_type = self.get_mime_type_for(file_name)
file_id = self.check_file_exist(file_name,parents,mime_type)
if file_id == None:
print "creating file...........",file_name
print "mime_type",mime_type
media = MediaFileUpload(file_name, mimetype=mime_type, resumable=True)
body = {
'title': file_name,
'description': 'A test document',
'mimeType': mime_type
}
if not parents == None:
body['parents'] = [{'id': parents}]
f = self.drive_service.files().insert(body=body, media_body=media).execute()
else:
print "file exists........... updating"
self.update_file(file_id, file_name)
此代码适用于较小的文件(测试高达25MB) . 但如果我试图上传大文件(70MB),系统会给出错误信息
回溯(最近的呼叫最后):
文件“googledrive.py”,第176行,在gd.upload_file(“test.mp4”,“/ media / media”)文件“googledrive.py”,第122行,在upload_file中f = self.drive_service.files() .insert(body = body,media_body = media).execute()文件“/usr/local/lib/python2.7/dist-packages/oauth2client/util.py”,第132行,在positional_wrapper中返回包装(* args, ** kwargs)文件“/usr/local/lib/python2.7/dist-packages/apiclient/http.py”,第688行,执行_,body = self.next_chunk(http = http,num_retries = num_retries)文件“/usr/local/lib/python2.7/dist-packages/oauth2client/util.py”,第132行,在positional_wrapper中返回包装(* args,** kwargs)文件“/usr/local/lib/python2.7 /dist-packages/apiclient/http.py“,第867行,在next_chunk headers = headers中)文件”/usr/local/lib/python2.7/dist-packages/oauth2client/util.py“,第132行,在positional_wrapper中return wrapped(* args,** kwargs)file“/usr/local/lib/python2.7/dist-packages/oauth2client/client.py”,第490行,在new_request重定向中,connection_type)文件“/ usr / local /里b / python2.7 / dist-packages / httplib2 / init.py“,第1570行,请求(响应,内容)= self._request(conn,authority,uri,request_uri,method,body,headers,redirections,cachekey)文件“/usr/local/lib/python2.7/dist-packages/httplib2/init.py”,第1317行,在_request(响应,内容)= self._conn_request(conn,request_uri,method,body,headers)文件“/usr/local/lib/python2.7/dist-packages/httplib2/init.py”,第1286行,在_conn_request响应中= conn.getresponse()文件“/usr/lib/python2.7/httplib.py” ,第1045行,在getresponse response.begin()文件“/usr/lib/python2.7/httplib.py”,第409行,在开始版本,状态,原因= self._read_status()文件“/ usr / lib / python2.7 / httplib.py“,第373行,在_read_status中引发BadStatusLine(行)httplib.BadStatusLine:''
1 回答
如果您的上传时间超过一小时,您的令牌可能会过期,您的下载将失败 . 这是一个已知的issue .
另外,请参阅Google Mirror API throwing BadStatusLine exception (Python)