0

I'm trying to make a script to process a lot of files on a Shared Drive using the wrapper PyDrive for Google Drive API. I can get the files loaded into a nested dictionary just fine, but when I try to change the metadata, the file (referenced by ID) cannot be found. There are several similar questions on here, I think I've reviewed and tried them correctly.

I've tried including these parameters, seemed to do the trick when getting the files in the first place:

file_list = drive.ListFile({
                            'q': "title contains 'PORTMUZ' and trashed=false", 
                            'supportsAllDrives' : True, 
                            'includeItemsFromAllDrives' : True, 
                            'corpora' : 'drive', 
                            'driveId' : portmuz_id
                            }).GetList()

This is the entire function, I'm still getting it to work but for now it's set to only change the name:

def move_to_archive():
for key, data in index.items():
    if index[key]['active'] == False and index[key]['parents'] == alle_leerlingen_id and 'TEST' in key:
        print(key, 'is geen huidige leerling meer maar staat nog in de map Portfolio/Alle Leerlingen. Verplaatsen naar archief?')
        if choose() == True:
            file = drive.CreateFile({
                                    'id': index[key]['id']
                                    })
            file['title'] = 'JEP'
            file.Upload(param={
                            'supportsAllDrives' : True, 
                            'includeItemsFromAllDrives' : True, 
                            'supportsTeamDrives' : True,
                            'corpora' : 'drive', 
                            'driveId' : portmuz_id
                            })
            index[key]['parents'] == portmuz_archief_id

I've checked the ID that the error returns, it is correct.

Traceback (most recent call last):
  File "script3.py", line 135, in <module>
    main()
  File "script3.py", line 124, in main
    move_to_archive()
  File "script3.py", line 96, in move_to_archive
    print(file.FetchMetadata())
  File "C:\Users\ict\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pydrive\auth.py", line 75, in _decorated
    return decoratee(self, *args, **kwargs)
  File "C:\Users\ict\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pydrive\files.py", line 239, in FetchMetadata
    raise ApiRequestError(error)
pydrive.files.ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/1E80Hp4WJI_ivirQ9TJCCzlFU0ykvDsWH?alt=json returned "File not found: 1E80Hp4WJI_ivirQ9TJCCzlFU0ykvDsWH">
Sandr
  • 11
  • 3
  • What is the metadata you change? Maybe when you perform changes on the files, they change parents? – ziganotschka Oct 28 '20 at 10:25
  • @ziganotschka Right now only the name changes, parents stay the same. If I can get that to work I would change the parents with this function. – Sandr Oct 29 '20 at 12:48
  • I am wondering if once you change the parents the `driveId` is not the same anymore. What I can see from your code is that you use `drive.CreateFile()` - so you are creating a new file. The new file will have a new id. Sorry if I misunderstood the problem setting, maybe you can give more details for clarification what exactly you are trying to do and what the problem is (and at what step). – ziganotschka Oct 30 '20 at 09:11
  • @ziganotschkaI think the idea is that you first locally create an object with the same ID as the one online you want to reference. Then you change it's metadata and call .Upload() to call the API and process the changes. – Sandr Nov 02 '20 at 08:26

0 Answers0