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!
Related
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
I have a small application that I have made. It basically copies a zip file from a network location to the computer that is running the application, unzips it in a folder and then creates a shortcut on the desktop.
Most of the time (I'd say about 80%) it works as intended. The other 20% of the time the stack trace it says it cannot create a file. It is always the same (_bz2.pyd). If I close it and run it again it works fine after this happens.
Anyone have any ideas of what is going on? Here is the code that extracts the file. I've even made the script try and extract the file, check if it worked, try and extract the file again. This hasn't solved the issue:
print ('uncompressing databases. This takes a few minutes')
# file_name = settings.working_folder + r'\UAT_Databases.zip'
temp_name = settings_dict['working_folder'] + settings_dict['file_name']
zip_ref = zipfile.ZipFile(temp_name, 'r')
zip_ref.extractall(settings_dict['install_folder'])
zip_ref.close()
logr.info('unzipped databases')
Here is the stack trace:
Traceback (most recent call last):
File "temp_installer.py", line 141, in unzip_databases
File "zipfile.py", line 1347, in extractall
File "zipfile.py", line 1335, in extract
File "zipfile.py", line 1398, in _extract_member
PermissionError: [Errno 13] Permission denied: 'C:\\TempApps\\Temp_application\\_bz2.pyd'
2020-03-03 11:36:25,697 : ERROR : __main__ : could not unzip databases
Traceback (most recent call last):
File "temp_installer.py", line 141, in unzip_databases
File "zipfile.py", line 1347, in extractall
File "zipfile.py", line 1335, in extract
File "zipfile.py", line 1398, in _extract_member
PermissionError: [Errno 13] Permission denied: 'C:\\TempApps\\Temp_application\\_bz2.pyd'
Here is my sample Python script where I want to download a file from SFTP server to my local.
srv = pysftp.Connection(host=host, username=username, password=password, port=port, cnopts=connOption)
with srv.cd(sftppath):
data = srv.listdir()
try:
for infile in data:
print infile
srv.get(infile, destination, preserve_mtime=True)
I can connect successfully and it lists all files in the folder. But when I use srv.get() to download to my desktop I get following error,
IOError: [Errno 21] Is a directory: '/Users/ratha/Desktop'
Error stack;
Traceback (most recent call last):
File "/Users/ratha/PycharmProjects/SFTPDownloader/handler.py", line 9, in <module>
main()
File "/Users/ratha/PycharmProjects/SFTPDownloader/handler.py", line 5, in main
downloadSFTPFiles()
File "/Users/ratha/PycharmProjects/SFTPDownloader/Utilities/SFTPConnector.py", line 49, in downloadSFTPFiles
srv.get(infile, destination, preserve_mtime=True)
File "/Users/ratha/PycharmProjects/SFTPDownloader/venv/lib/python2.7/site-packages/pysftp/__init__.py", line 249, in get
self._sftp.get(remotepath, localpath, callback=callback)
File "/Users/ratha/PycharmProjects/SFTPDownloader/venv/lib/python2.7/site-packages/paramiko/sftp_client.py", line 801, in get
with open(localpath, "wb") as fl:
IOError: [Errno 21] Is a directory: '/Users/ratha/Desktop'
What Im doing wrong here?
The stack trace is actually really clear. Just focus on these two lines:
with open(localpath, "wb") as fl:
IOError: [Errno 21] Is a directory: '/Users/ratha/Desktop'
Clearly, pysftp tries to open /Users/ratha/Desktop as a file for binary write, which didn't go well because that is already, well, a directory. The documentation will confirm this:
localpath (str) – the local path and filename to copy, destination. If not specified, file is copied to local current working directory
Therefore you need to figure out the file name you want to save as, and use (best practice) os.path.join('/Users/ratha/Desktop', filename) to get a path and filename, instead of just a path.
Your destination variable should hold the path to the target file, with the file name included. If the target file name is to be the same as the source file name, you can join the base name of the source file name with the target directory instead:
import os
...
srv.get(infile, os.path.join(destination, os.path.basename(infile)), preserve_mtime=True)
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')
^
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.