Python 3.6.1 - PermissionError: [Errno 13] Permission denied shown when trying to unzip a file
Solution 1
I had a similar problem trying to write to a file.
The fix that worked for me:
Right-click your PyCharm application and run it as administrator.
Solution 2
I run into the same error when unzipping the folder "temp.zip" and only extract the file . In my case I had a directory with a folder "temp" and a zip file called "temp.zip".
def unzip(path, filename):
with ZipFile(path, 'r') as zipobj:
zipobj.extract(member=filename)
When I run this file, I got the error message:
...
"test.py", line 259, in unzip
with ZipFile(path, 'r') as zipobj:
File "C:\Program Files\Python36\lib\zipfile.py", line 1090, in __init__
self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied
The problem is, that zipobj.extract()
needs to create a folder called temp and extract the content (temporarly). But this folder already exists. --> There I got the permission denied error.
Solution:
- either delete the folder "temp"
- or move the zip first to another directory and unzip it there
Solution 3
I guess it's because your dictionary is on the C drive (the windows disk ,sometimes it's forbidden to write and erase) , if you changed to the D drive, it maybe work .
undetected Selenium
A full stack test automation engineer and a web security analyst working with Selenium (Java/Python). Owner of Selenium room & top answerer in selenium and selenium-webdriver tags. If any of my discussion / article was helpful, you may like to... | or you can also |GPay If any of your question wants my attention you can email me at debanjan[dot]selenium[at]gmail[dot]com. You can Send a Thank You note to me! too... I'm reachable through LinkedIn
Updated on June 04, 2022Comments
-
undetected Selenium almost 2 years
I am facing a PermissionError while I am trying to extract a zip file. I have gone through a lot of discussion threads here on SO but still unable to solve my issue.
Currently I am working with Python 3.6.1 on a Windows 8 box. I have created a new directory through the following code:
import os,zipfile newpath = 'C:\\home\\vivvin\\shKLSE' #newpath = r'C:\\home\\vivvin\\shKLSE' if not os.path.exists(newpath): os.makedirs(newpath)
Next I have downloaded a zip file and saved into
newpath
directory.Now I am trying to extract all the files (10 csv files) within the zip file to be extracted into the
newpath
directory. To achieve that I have written the following code:import os,zipfile newpath = 'C:\\home\\vivvin\\shKLSE' path_to_zip_file = newpath directory_to_extract_to = newpath #zip_ref = zipfile.ZipFile(newpath, 'r') zip_ref = zipfile.ZipFile(newpath, 'w') zip_ref.extractall(newpath) zip_ref.close()
But each time I am getting an error as:
Traceback (most recent call last): File "C:/Users/AtechM_03/PycharmProjects/Webinar/SeleniumScripts/extract.py", line 6, in <module> zip_ref = zipfile.ZipFile(newpath, 'w') File "C:\Python\lib\zipfile.py", line 1082, in __init__ self.fp = io.open(file, filemode) PermissionError: [Errno 13] Permission denied: 'C:\\home\\vivvin\\shKLSE'
I have observed the properties manually of the zip file and seems there is a Security message along with a
Unblock
button. As of now I am clueless how toUnblock
it.Can anyone help me out please? Thanks in advance.
-
Exprator almost 7 yearsPycharm dont have permission, try opening cmd after right click and then run as administrator then go to the python program folder and run your file
-
undetected Selenium almost 7 years@Exprator Thanks for the quick look. But I am doing a lot other stuff through PyCharm with Selenium. Is there a way I can achieve the permission? Thanks
-
Exprator almost 7 yearsWell you can give permission while creating the folder. Check for os permission giving in python
-
undetected Selenium almost 7 years@Exprator The permission issue is not with the directory but with the downloaded zip file. Thanks
-
stovfl almost 7 yearsWhere is the filename of the
zip file
in your script? -
undetected Selenium almost 7 years@stovfl Thanks a lot for pointing that out. What if I am not sure about the exact file name? But definitely I am sure about the zip type of file.
-
stovfl almost 7 yearsRead about using
*.zip
: docs.python.org/3/library/glob.html#module-glob -
undetected Selenium almost 7 years@stovfl Thanks for pointing to the required document. I will get back to you after going through that. Thanks
-