Exec Node to start Python Script - permission error

Hi,

I'm trying to write to a .txt file from a python script, then use node red to read the contents of the file. The issue I'm having is running the python script from the Exec node. It appears to run the script but is returning a permissions error for the .txt file.

The command I'm using is:

python /home/pi/Desktop/Keypad/doorKeypad.py

Has anyone got any ideas why the permissions error is occuring? It runs fine if I start it manually through the Python Idle.

Thanks,
Gregor

Has the user running node-red got write access permissions to the folder being written to?
If you logon as that user in a terminal and then run the python command is it ok?

Hi Colin,
Thanks for your response. How would I find out the permissions of the node red user?

Looking at the file path I assume that you are using a Pi, are you using Raspbian?
Do you know which user is running node-red? If not how did you install node-red and how are you running it?

Yeah I'm using a 3B+, using the standard rasbian image. Signed in as Pi user.

You haven't answered that question.

You haven't answered that question either.

Furthermore (after you answer Colin’s other questions), what are the permissions/ownership of the file
/home/pi/Desktop/Keypad/doorKeypad.py, and where is it trying to write the txt file to (and what are the permissions/ownership of that folder?

Hi Colin, when I run the code from the command line it is giving me the same error. When I add sudo to the front of it, it appears to run but the text file is not created/amended. I didn't need to install node-red as it is part of the raspbian image. I ran it by signing is as pi user and typing node-red-start.

afelix, I created both the file and folder while signed in as the pi user. It is trying to write the .txt file to the /home/pi/Desktop/Keypad folder.

Is there any other information I can provide to help?

Thanks,
Gregor

I managed to fix this. I went into the properties of the file, and set its permissions to Anyone can change it. I also changed my python script so that it had the full file path. This now appears to be working.

Thanks for your help.

You can find the recommended way of installing and upgrading node red (which will ensure you get the latest version and also that you will have recommended versions of npm and nodejs) at Running on Raspberry Pi : Node-RED

I suspect that means that at some point you ran your script with sudo, so that the file had root ownership, preventing the user pi from writing to it.

2 Likes