Skip to content Skip to sidebar Skip to footer

Google Drive Api 'md5checksum' Does Not Work On Python

I am working on a script to look for duplicated files and I am trying to use 'md5Checksum' but reports me a KeyError. Do you know if it really works? Thank you for your time. FILES

Solution 1:

From the Google Drives API V3:

md5Checksum - string - The MD5 checksum of the revision's content. This is only applicable to files with binary content in Drive.

So if your document does not contain binary data, there will not be an md5Checksum field in the metadata. The Google Drives API V2 explicitly said that it was not populated for Google Documents:

md5Checksum - string - An MD5 checksum for the content of this file. This field is only populated for files with content stored in Drive; it is not populated for Google Docs or shortcut files.

It is not obvious why they removed the reference to Google Documents in the V3 API. Either way it is clear that the md5Checksum field will not be populated for every file, so you should use something like:

iffi['title'] == "Test":
    print('The name is: %s and md5 is: %s' % (fi['title'], fi.get('md5Checksum'))

This avoids throwing the exception and returns None as expected if the field is not populated.

Post a Comment for "Google Drive Api 'md5checksum' Does Not Work On Python"