0

我正在尝试通过 Microsoft Flow 的过程下载一个填充到 Google Drive 文件夹的 .csv 文件,该过程每 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
4

1 回答 1

0

您可能需要指定文件的MIME类型以确保正确下载文件。如果您绝对确定该文件是 acsv并且未转换为 Google 文档,那么您可以执行以下操作:

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'})
file_obj.GetContentFile('Assigned_Agency_AZS_Overhead_EXCEL.csv', mimetype='text/csv')
于 2018-11-02T15:43:30.847 回答