我正在使用pyDrive库,现在我需要获取xmls文件并读取它但我有错误
pydrive.files.FileNotDownloadableError:没有downloadLink / exportLinks 对于在元数据中找到的mimetype
white_list_xmls - 我的xmls文件
我的代码:
tmp_name = None
with NamedTemporaryFile(delete=False, suffix='.xlsx') as tf:
tf.write(white_list_xmls.GetContentFile(white_list_xmls['title']))
tf.flush()
tmp_name = tf.name
if tmp_name is not None:
print(tmp_name)
然后我改变了这样的代码:
tmp_name = None
with NamedTemporaryFile(delete=False, suffix='.xlsx') as tf:
mimetypes = {
'application/vnd.google-apps.document': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.google-apps.spreadsheet': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
}
if white_list_xmls['mimeType'] in mimetypes:
download_mimetype = mimetypes[white_list_xmls['mimeType']]
tf.write(white_list_xmls.GetContentFile(white_list_xmls['title'], mimetype=download_mimetype))
tf.flush()
tmp_name = tf.name
if tmp_name is not None:
print(tmp_name)
但我也有错误:
TypeError:需要类似字节的对象,而不是' NoneType'