0

我正在使用pyDrive库,现在我需要获取 xmls 文件并阅读它,但我有一个错误

pydrive.files.FileNotDownloadableError:在元数据中找不到 mimetype 的 downloadLink/exportLinks

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”

4

0 回答 0