【发布时间】:2018-11-02 15:31:30
【问题描述】:
我正在尝试下载一个 .csv 文件,该文件通过 Microsoft Flow 的过程填充到 Google Drive 文件夹中,该过程每 6 小时通过电子邮件检索一个电子邮件附件文档。我试图遵循使用 Pydrive 模块的文档。我知道如何创建文件以上传和下载到 Google Drive,但不知道如何根据现有文件的链接 URL 下载。这是我的代码。
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file_obj = drive.CreateFile({'id': '1j2vJVOB-_Xltmp9xkQJZzGb-5DAB_Imu'})
print(file_obj["title"], file_obj["mimeType"])
file_obj.GetContentFile('Assigned_Agency_AZS_Overhead_EXCEL.csv', mimetype='text/csv')
我收到的错误消息是。
runfile('C:/Google_Python_Test/Google/Google_Drive1.py', wdir='C:/Google_Python_Test/Google')
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?client_id=1078392182164-kone7oddogt31qfcg1qvp5u13fc3tivi.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&response_type=code
Authentication successful.
Overhead application/vnd.google-apps.folder
Traceback (most recent call last):
File "<ipython-input-26-6344c96b3f6e>", line 1, in <module>
runfile('C:/Google_Python_Test/Google/Google_Drive1.py', wdir='C:/Google_Python_Test/Google')
File "C:\Users\shrevee\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "C:\Users\shrevee\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Google_Python_Test/Google/Google_Drive1.py", line 11, in <module>
file_obj.GetContentFile('Assigned_Agency_AZS_Overhead_EXCEL.csv', mimetype='text/csv')
File "C:\Users\shrevee\Anaconda3\lib\site-packages\pydrive\files.py", line 210, in GetContentFile
self.FetchContent(mimetype, remove_bom)
File "C:\Users\shrevee\Anaconda3\lib\site-packages\pydrive\files.py", line 43, in _decorated
return decoratee(self, *args, **kwargs)
File "C:\Users\shrevee\Anaconda3\lib\site-packages\pydrive\files.py", line 265, in FetchContent
'No downloadLink/exportLinks for mimetype found in metadata')
FileNotDownloadableError: No downloadLink/exportLinks for mimetype found in metadata
【问题讨论】:
-
您确定文件是 csv 并且 id 正确吗?还是该文件是 Google mime 类型的?
-
是的,文件是 csv,以及正确的文件 ID。
-
@EricShreve 如打印输出所示,给出的文件 ID 实际上不正确,它是文件夹“开销”的 ID,这就是您收到错误的原因。
标签: python python-3.x google-drive-api pydrive google-python-api