"[Errno 13] Permission denied: - python

This may be a redundant question, but i tried several approaches for example starting PyCharm as Admin or changed filenames but i am still getting the Errno 13 error and getting frustrated:
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\YouTubePersonalisierung\main.py", line 124, in
userobject.closeDriver()
File "C:\Users\User\PycharmProjects\YouTubePersonalisierung\thirdPartySimulation.py", line 81, in closeDriver
shutil.copytree(mozprofile, path)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 554, in copytree
return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 510, in _copytree
raise Error(errors)
shutil.Error: [('C:\\Users\\User\\AppData\\Local\\Temp\\rust_mozprofile8rq2NB\\parent.lock', 'C:/Users/User/AppData/Roaming/Mozilla/Firefox/Profiles/ynophskl.Test-Nutzer\\parent.lock', "[Errno 13] Permission denied: 'C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Temp\\\\rust_mozprofile8rq2NB\\\\parent.lock'")]
Here is the code where the error occurs:
def closeDriver(self):
mozprofile = self.driver.capabilities["moz:profile"]
print(mozprofile)
try:
os.remove(mozprofile + "/lock")
os.remove()
except:
pass
print(is_admin())
path = profilePath + self.profileName
print(path)
if os.path.exists(path):
shutil.rmtree(path)
shutil.copytree(mozprofile, path)
EDIT: maybe found a solution now changed the last line to:
shutil.copytree(mozprofile, path, ignore = shutil.ignore_patterns("parent.lock","lock", ".parentlock"))
Now no error occurs but i don't really understand how this prevents the permission error
EDIT2: So ignore means file with the pattern is not copied, so i guess while i get no error my problem that the file is not copied is still existing
EDIT3: so ignore just sort about the files but Not the whole directory tree so i guess the permission error Really was a mozilla Firefox error

Related

Permission denied when trying to copy files

Using the script:
file = os.path.join(subfolder_name, list_of_files[i])
for dest_folder_finetune, dest_folder_relab in zip(finetune_datasets, relab_datasets):
copy(file, dest_folder_finetune)
copy(file, dest_folder_relab)
every 20 iterations, I am having a permission denied problem. The stack, looks something like:
Traceback (most recent call last):
File "/home/revan/boosting_classifier_with_games/dataset_creator.py", line 72, in <module>
main()
File "/home/revan/boosting_classifier_with_games/dataset_creator.py", line 24, in main
create_test_and_relab(list_of_subfolders)
File "/home/revan/boosting_classifier_with_games/dataset_creator.py", line 66, in create_test_and_relab
copy(file, dest_folder_finetune)
File "/home/revan/anaconda2/envs/pytorch/lib/python2.7/shutil.py", line 119, in copy
copyfile(src, dst)
File "/home/revan/anaconda2/envs/pytorch/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/sun_btbivuchmkkzetpo.jpg'
The 'funny' thing is that I definitely have all permissions for that file. Furthermore, I tried to copy it manually, and I can do it without problem. If I randomize the process, the same file gets copied, but then some other file (after 20 iterations) cannot be copied.
PS: Changing copy to copy2, gives the exact same problem.
Has anyone experienced anything similar in the past? Could it be a Python or a Linux problem?
One of your datasets has a bad folder name, which is setting the destination to the root of the file system.
To just get it working, you can skip when it's trying to copy to the root:
import os
file = os.path.join(subfolder_name, list_of_files[i])
for dest_folder_finetune, dest_folder_relab in zip(finetune_datasets, relab_datasets):
if os.path.abspath(dest_folder_finetune) != "/":
copy(file, dest_folder_finetune)
else:
print("Warning, path {} for dest_folder_finetune writes to the root of the filesystem".format(dest_folder_finetune))
if os.path.abspath(dest_folder_relab) != "/":
copy(file, dest_folder_relab)
else:
print("Warning, path {} for dest_folder_relab writes to the root of the filesystem".format(dest_folder_relab ))
However, if this is more than a live once script, I suggest scrubbing and verifying the dataset beforehand instead.
try with "sudo python filename.py"

How do I make my program move files without the .py file being in the source location

I wrote this program to move videos from my download folder to different destination folders.
import os
import shutil
import sys
folder = []
highlight = ['highlights','goals','skills']
comedy_word = ['comedy', 'acapella','seyilaw','basketmouth','basket mouth','bovi','gordons','buchi','rhythm unplugged','elenu','seyi law','akpororo','emmaohmygod','klint','shakara','funnybone','igodye','i go die','i go dye','igodye','whalemouth','whale mouth','daniel']
series_word = ['lost', 'thrones', 'vampire', 'originals', 'ship', '']
grub_word = ['programming', 'python', 'linux','exploit','hack']
for i in os.listdir('C:\\Users\\Afro\\Downloads\\Video'):
folder.append(i.lower())
def tv_series(series):
for serie in series:
if 'ship' in serie:
shutil.move(serie, 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\The Last Ship\\The Last Ship 3\\' )
print(serie[:-3] +': Moved!')
elif 'lost' in serie:
shutil.move(serie, 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\Lost\\s2\\' )
print(serie[:-3] +': Moved!')
The file's name is arrange.py and the program throws a filenotfound error when arrange.py is not in the "C:\Users\Afro\Downloads\Video" folder. Is it possible to make the program run in any folder?
Thanks
Here's the error it throws.
Traceback (most recent call last):
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 538, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'lost - s02e08 (o2tvseries.com).mp4' -> 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\Lost\\s2\\lost - s02e08 (o2tvseries.com).mp4'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Afro\Desktop\Arrange.py", line 77, in <module>
start(folder)
File "C:\Users\Afro\Desktop\Arrange.py", line 65, in start
tv_series(folder)
File "C:\Users\Afro\Desktop\Arrange.py", line 22, in tv_series
shutil.move(serie, 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\Lost\\s2\\' )
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 552, in move
copy_function(src, real_dst)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 251, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 114, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'lost - s02e08 (o2tvseries.com).mp4'
You call shutil.move specifying the reference point incorrectly. In your loop that gathers the files, you should use os.path.join('C:\\Users\\Afro\\Downloads\\Video', i) and put that in your list instead. Otherwise it's all relative paths, hence the FileNotFound error.
You could also change the working directory. This would make the script behave as if it was in a different folder. This can have some unintended consequences, so be careful. Details here.
Hope this helps!

IOError: [Errno 13]

I am trying to download a link and place it in the downloads folder, however I get a permission error. I am an admin user on the computer and I also ran it in administrator mode. Still I get the same error.
Here is the code I use:
urllib.urlretrieve(link, r"C:\Users\%s\Downloads" % (user))
Here is the error I get:
Traceback (most recent call last):
File "C:\Users\Grant\Desktop\FTB Server Updater\FTB Updater_v1.0.py", line 28, in <module>
getNewServer(link)
File "C:\Users\Grant\Desktop\FTB Server Updater\FTB Updater_v1.0.py", line 22, i getNewServer
urllib.urlretrieve(lynk, r"C:\Users\%s\Downloads" % (user))
File "C:\Python27\lib\urllib.py", line 94, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\Python27\lib\urllib.py", line 244, in retrieve
tfp = open(filename, 'wb')
IOError: [Errno 13] Permission denied: 'C:\\Users\\Grant\\Downloads'
Shouldn't urllib.urlretrieve(link, r"C:\Users\%s\Downloads" % (user)) be urllib.urlretrieve(link, r"C:\Users\%s\Downloads\SAVE_FILE_NAME" % (user))? You are trying to overwrite the Downloads directory, which I am not sure Windows would allow. It might be possible in unix if you have permissions, but Windows might stop you from doing that!

IOError: [Errno 13] Permission denied

I'm getting a permission error when trying to save a screenshot from Sikuli under Windows. The code that's doing the capturing is:
def CaptureScreenshot(self):
resultsDirectory = os.path.join('C','08 May 2013 11 34','myname.png')
screenshot = capture(self.screen)
print(screenshot)
shutil.move(screenshot,self.resultsDirectory)
When I print the screenshot path returned by capture, I get
D:\DOCUME~1\BUNNINGS\LOCALS~1\Temp\sikuli-scr-366782306192033926.png
When I run the code, I get this error:
Traceback (most recent call last):
File "__pyclasspath__/Tests/Tests.py", line 12, in tearDown
File "__pyclasspath__/Scripts/Screen.py", line 39, in CaptureScreenshot
File "C:\jython2.5.3\Lib\shutil.py", line 205, in move
copy2(src,dst)
File "C:\jython2.5.3\Lib\shutil.py", line 96, in copy2
copyfile(src, dst)
File "C:\jython2.5.3\Lib\shutil.py", line 52, in copyfile
fdst = open(dst, 'wb')
IOError: [Errno 13] Permission denied: 'C\\08 May 2013 11 34\\myname.png'
The destination folder exists and myname.png is the new name I am trying to give to the image.
I noticed that the destination folder's properties are set to "read only". Is this causing the issue? I couldn't change the readonly attribute; when I try, it just goes back to readonly.
There seems to be a colon missing after the C in your path. You are now trying to write in a subdirectory 'C' of the current directory.
Try to change the second line into:
resultsDirectory = os.path.join('C:','08 May 2013 11 34','myname.png')
^

Permission Denied error while downloading file from Dropbox in Python

Through the metadata of one folder, I am able to get relative file paths of the files I want to download to my local machine. When I give this path to source code of do_get(), it gives me permission denied error. Here is the code which is supposed to download files and decrypt them but its not able to download the files on the first hand.
#command
def do_decryptFiles(self, from_path, to_path, key):
"""
Decrypt all the files given in the folder and subfolders of from_path
Examples:
Dropbox> decryptFiles '/Photos' 'E:\temp' 'a13223132323232'
"""
folder_metadata = self.api_client.metadata(from_path)
print "metadata:", folder_metadata
for s in folder_metadata['contents']:
if(s['is_dir'] == True):
print "directory:", s['path']
else:
FFPath = s['path']
print FFPath
do_get(self, from_path, to_path)
to_file = open(os.path.abspath(to_path), "wb")
f, metadata = self.api_client.get_file_and_metadata(self.current_path + FFPath)
to_file.write(f.read())
When it calls open(), command line gives me Permission Denied error. Any help would be appreciated.
Traceback (most recent call last):
File "example/cli_client.py", line 397, in <module>
main()
File "example/cli_client.py", line 394, in main
term.cmdloop()
File "C:\Python27\lib\cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "C:\Python27\lib\cmd.py", line 219, in onecmd
return func(arg)
File "example/cli_client.py", line 77, in wrapper
return f(self, *args)
File "example/cli_client.py", line 315, in do_decryptFiles
to_file = open(os.path.abspath(to_path), "wb")
IOError: [Errno 13] Permission denied: 'E:\\proto'
Sounds a local directory permissions issue? I had similar problem recently, if it is there are some possible solutions here.
It sounds to me like this isn't a Dropbox API issue, it's a local IO Error.

Categories

Resources