You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As written the crud_object.py file main function will fail with this error (on windows at least):
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\owner\\AppData\\Local\\Temp\\tmp3preaezj'
Traceback (most recent call last):
File "crud_object.py", line 150, in <module>
main(args.bucket, args.filename, args.reader, args.owner)
File "crud_object.py", line 47, in main
if not filecmp.cmp(filename, tmpfile.name):
File "E:\Python\Python35\lib\filecmp.py", line 62, in cmp
outcome = _do_cmp(f1, f2)
File "E:\Python\Python35\lib\filecmp.py", line 75, in _do_cmp
with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2:
The issue is that NamedTemporaryFile keeps the file handle open so that when filecmp attempts to open it, it will fail with a permission denied error. The correct way to do this is shown below:
print('Fetching object..')
with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as tmpfile:
get_object(bucket, filename, out_file=tmpfile)
tmpfile.seek(0)
tmpName = tmpfile.name
if not filecmp.cmp(filename, tmpName):
raise Exception('Downloaded file != uploaded object')
print('Deleting object..')
os.remove(tmpName)
The text was updated successfully, but these errors were encountered:
In which file did you encounter the issue?
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/api/crud_object.py
Describe the issue
As written the crud_object.py file main function will fail with this error (on windows at least):
The issue is that NamedTemporaryFile keeps the file handle open so that when filecmp attempts to open it, it will fail with a permission denied error. The correct way to do this is shown below:
The text was updated successfully, but these errors were encountered: