-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
When using the MediaFileUpload class to upload files to Google Drive via google-api-python-client, the file remains open after the upload completes, resulting in a PermissionError when I attempt to delete the file.
Code example:
from googleapiclient.http import MediaFileUpload
file_metadata = {'name': "file.zip"}
media = MediaFileUpload('D:\\file.zip', mimetype='application/zip', resumable=True)
request = drive.files().create(body=file_metadata, media_body=media)
response = request.execute()
os.remove('D:\\file.zip') # Raises PermissionError
Expected behavior: The file should automatically close after uploading so that it can be deleted without errors.
Actual behavior: The file remains open, and attempting to delete it results in a PermissionError.
Solution: I resolved the issue manually by adding media._fd.close() after the upload completes to close the file.
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.