this is the original InsertPermission method in files.py from PyDrive package:
def InsertPermission(self, new_permission):
"""Insert a new permission. Re-fetches all permissions after call.
:param new_permission: The new permission to insert, please see the
official Google Drive API guide on permissions.insert for details.
:type new_permission: object
:return: The permission object.
:rtype: object
"""
file_id = self.metadata.get('id') or self['id']
try:
permission = self.auth.service.permissions().insert(
fileId=file_id, body=new_permission).execute(http=self.http)
except errors.HttpError as error:
raise ApiRequestError(error)
else:
self.GetPermissions() # Update permissions field.
return permission
it only accepts your permission dict
{
'type': 'user',
'value': 'myemail@gmail.com',
'role': 'reader'
}
as the body of API requests (and no other arguments accepted as parameters).
while according to Google Drive API Documentation, the sendNotificationEmails is a query parameter that you can not
find it in PyDrive's InsertPermission method.
To temporarily fix this problem I would suggest adding this parameter in the InsertPermission method and manually setting a
sendNotificationEmails parameter that is used from Google Drive API in files.py of the PyDrive package.
def InsertPermission(self, new_permission, sendNotificationEmails: bool = True):
"""Insert a new permission. Re-fetches all permissions after call.
:param new_permission: The new permission to insert, please see the
official Google Drive API guide on permissions.insert for details.
:type new_permission: object
:return: The permission object.
:rtype: object
"""
file_id = self.metadata.get('id') or self['id']
try:
permission = self.auth.service.permissions().insert(
fileId=file_id, body=new_permission, sendNotificationEmails=sendNotificationEmails).execute(
http=self.http)
except errors.HttpError as error:
raise ApiRequestError(error)
else:
self.GetPermissions() # Update permissions field.
return permission
Or you can try to replace your codes from PyDrive with codes from Google Drive documentation. In this case, you would be
easier to find why the error occurred, and always has detailed documentation that you could refer to.
Hope it helps you.