您好我尝试使用以下代码将文件上传到Google云端硬盘
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”, “/媒体/介质”)
文件“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行,位于position_wrapper
return wrapped(* 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行,位于position_wrapper
return wrapped(* args,** kwargs)
文件“/usr/local/lib/python2.7/dist-packages/apiclient/http.py”,第867行,在next_chunk中
头=头)
文件“/usr/local/lib/python2.7/dist-packages/oauth2client/util.py”,第132行,位于position_wrapper
return wrapped(* args,** kwargs)
文件“/usr/local/lib/python2.7/dist-packages/oauth2client/client.py”,第490行,in new_request
重定向,connection_type)
文件“/usr/local/lib/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
response = 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: ''
答案 0 :(得分:2)
如果上传时间超过一小时,您的令牌可能会过期,您的下载将失败。这是一个已知的issue。
另请参阅Google Mirror API throwing BadStatusLine exception (Python)