I am having permission issues with a python program executed via script via launchd.
If I run the .sh script from Terminal, or from BBEdit, it executes OK.
When run from launchd, I get:
with open(_userHome + '/Downloads/quotes.csv', newline='') as chkFile:
PermissionError: [Errno 1] Operation not permitted: '/Users/xxx/Downloads/quotes.csv'
Permissions on the download folder give the user r/w and everyone read access.
I tried adding python3 to security with full disk access using /usr/local/bin/python3.
This is specific to the 'Downloads' folder. I created a 'Downloads2' folder and it worked fine. That is a terrible kluge. I should be able to use the default download folder.
Ideas ?
You're running a newer, more restrictive version of MacOS than I am.
Refer to https://nektony.com/duplicate-finder-free/folders-permission
for advice that goes beyond chmod a+r.
Tl;dr: SysPref --> Security&Privacy --> Privacy --> Files&Folders --> +
Related
So I wrote a deployment script in python that essentially just moves a bunch of directories around. It may or may not be relevant that I'm working on Windows and the scripts manipulates files and directories in Windows network shares.
A requirement of this script is it moves the old binary directory to a backup location on the same Windows network share, and that's where I'm having the problem. I'm using os.renames for this task. The destination path is generated based on the timestamp of the executable in the bin directory.
exec_mtime = datetime.fromtimestamp(os.path.getmtime(server_exec_path))
new_dirname = os.path.basename(target_path) + '_' + exec_mtime.strftime('%Y-%m-%d_%H.%M.%S')
backup_target_dir = os.path.join(server_old_dir_path, new_dirname)
if not os.path.exists(backup_target_dir):
print("{0}: Backing up old software...".format(server))
os.renames(server_target_path, backup_target_dir)
else:
print("{0}: A backup already exists with the same version number. Skipping backup.".format(server))
As for my variables:
target_path == "//server/share/path/to/bin"
server_exec_path == os.path.join(target_path, 'Program.exe')
server_old_dir_path == "//server/share/path/to/bin_backup"
The os.renames command would resolve to something like this:
os.renames("//server/share/path/to/bin", "//server/share/path/to/bin_backup\\bin_2019-11-01_13.02.27")
So, my problem is that os.renames always throws PermissionError: [WinError 5] Access is Denied. I have double-checked the permissions on all of these directories and I have them. Here are some things I have tried so far:
Performing the same moves in the Windows file browser. -> It works.
Running the same os.renames command in the python3 shell with the same arguments the script would give it. -> It works, confusingly.
Putting the os.renames command in a loop to retry it 100 times if it fails (I read somewhere that it can help sometimes). -> It fails.
Running the script in an elevated PowerShell. -> It fails.
Hitting my laptop with a sledgehammer. -> Haven't tried yet.
Another thing I want to mention is the script used to work not even a few days ago. I did make some edits in the meantime, but they weren't related to this section of code.
I'm out of ideas on this one. So any help you can provide would be much appreciated.
As it turns out, the problem was a side-effect of the changes I made to my script. I use python to launch a psexec command against the same remote machine earlier in the script (to run taskkill locally so the software I'm updating can exit gracefully), and I used the -u flag, which changes the user with which the command runs on the remote machine. When I removed the -u flag os.renames started working again. So I'm guessing that somehow running psexec changed the user the python script uses when running os.renames.
I've installed Python 3.8 on Win 10 machine. Path to Python is C:\Users\userid\AppData\Local\Programs\Python\Python38\
Path environment variable values are: C:\Users\userid\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe
In order to test python, I created a simple script called "script.py" in directory C:\python_scripts.
Then I tried to run "script.py" from the directory where it is located, but got error:
C:\python_scripts> python script.py
C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'script.py': [Errno 2] No such file or directory
What might be the cause of getting this error? i tried to run the script with both cmd and powershell, with the usual user rights and with elevated admin rights, still getting Errno 2.
No other versions of Python have been previously installed on this machine (which is a corporate one, if that might be significant)
Thank you
Thank you #OferSadan for your suggestion to use dir command, it helped me to solve the problem. The "script.py" had an additional .txt extension added to it for some reason, but the Windows explorer only showed .py extension by default. Now I deleted the trailing .txt suffix and the script runs
I have been trying to make a file in C drive but I am getting PermissionError using python 3.6. How can I fix this problem?
import os
os.mkdir('C:\\Program Files\\test_folder')
To modify C:\Program Files\, you need administrator permissions. So this is not specifically a Python problem.
Run your program from an administrator user, for instance by right-clicking and selecting Run as administrator or using runas in the console. You may also need to pass UAC.
I've recently installed backup manager onto my ubuntu machine to have automated backup going. The problem is when I go to set up the automatization using this code -
it comes us up saying this "bash: /etc/backup-manager.sh: Permission denied"
I do not understand this error. I've tried change the user who read/writes to someone other than root and that didn't work. I tried changed the chmod number from 770 to 700 and still didn't work.
any info on this is welcome. Thank you to those who help :)
those wondering I am using this tutorial giving to me by the host. https://documentation.online.net/en/dedicated-server/tutorials/backup/configure-backup/start
I'm using the desktop version of ubuntu 16 incase that is needed
The sudo doesn't do what you want in this case. What happens is that the shell evaluates the redirection and attempts to open the /etc/backup-manager.sh for you before the sudo cat even gets started. That fails because the shell still runs as you unprivileged user. You have to say sudo -i to open a new root shell, execute the commands and exit again.
Alternatively you could try sudo nano /etc/backup-manager.sh and paste the contents there. This would work because the editor is run as root and does the file opening itself when you save.
I was working with markdown file on RStudio. I have Ubuntu 14.04 on my laptop. I produce html files using knitr. I decided to clean my enviroment and added rm and gc commands at the end.
Now here is a message in my console window:
Error attempting to read history from ~/.Rhistory: permission denied (is the .Rhistory file owned by root?)
What it means? Is it bad for my code?
You are right - the first time you ran it, you were in sudo mode, and the .Rhistory file was created with root as the owner. Running RStudio as root would remove the symptom, but is not ideal. To be able to run it as a regular user, simply change the owner of the .Rhistory file:
sudo chown -c <user_name> .Rhistory
In the best traditions of stackoverflow I reply to my own question! The problem occurred because when I first started R, I did it as su:
sudo R
so I can load a lot of useful libraries in /usr/lib/R/site-library and not in my account. As result .Rhistory became su file. It is possible for RStudio to see it if it is started as
sudo rstudio
and then all is fine.