'Access Denied to zipfile created using python
I was able to create a zip file using the below code:
import os
import zipfile
user = input('Please enter your ID:')
date = input('Please enter the date:')
os.chdir('C:/Users/'+user+'/Desktop/Files/')
name = 'Position_'+date+'_Global'
newzip = zipfile.ZipFile(name+'.zip', 'w', zipfile.ZIP_DEFLATED)
newzip.write(name+'.txt')
print(newzip.infolist())
newzip.close()
The code runs successfully, but I am facing access denied error while trying to open the zip file.
Compressed (zipped) Folders Error:
Windows cannot open the folder.
Access to the Compressed (zipped) Folder 'C:/Users/XXXXX/Desktop/Files/Position__Global.zip' is denied.
I am not sure what is causing the issue. Could you please check?
Solution 1:[1]
My office IT team debugged this:
The issue was due to restrictions on user privileges on my office PC. It occurs when you have user access but the python is being executed as Administrator. Then the file created by the administrator will not be available to be opened by common user.
Solution 2:[2]
Most of time, it happened at some application open the file and not closed. Remember to close the opened file in your script, or try to close your application when failed before you close the opened file.
import zipfile
newzip = zipfile.ZipFile('D:/test.zip', 'w', zipfile.ZIP_DEFLATED)
newzip.write('D:/test.txt')
print(newzip.infolist())
# newzip.close()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Akash |
Solution 2 |