Exec node + Python3 Script on Ubuntu resulting in [Errno 13] Permission denied

Hi all,
New to Node-Red and Ubuntu but I was moving fine ... until i crashed! Hope that you can help me clarify an issue that has been torturing me for a couple of days:

The Intended Flow that is not working: [Inject node] sends “hello…” string → [Exec node] calls Python3 script and passes the payload as parameter - This returns a JSON string → [Debug node] shows the JSON string returned from Exec node.


The issue - Exec node returns permission error:

Command failed: python3 /home/alex/ac_work/python3/p3_test_1.py "Parameter-1"
python3: can't open file '/home/alex/ac_work/python3/p3_test_1.py': [Errno 13] Permission denied


Some facts:
1 - If I go to Terminal and type the command used in the “exec” node, the script runs properly. It takes the parameter and returns the JSON string. No issues.
2 - The directory where the python3 script is at has the following permissions:
alex@alex-FX6860:~/ac_work/python3$ ls -l
total 8
-rw-r--r-- 1 root root 14 Jun 8 20:10 nodered_created_file2.txt
-rwxrwxrw- 1 alex ac_nodered 422 Jun 8 16:15 p3_test_1.py
alex@alex-FX6860:~/ac_work/python3$
3 - I created a simple output to file using the [File node], and the “nodered_created_file2.txt” got created. Notice that it has “root” as both owner and group.
4 - Created a Group called ac_nodered (users alex and root), and this is the Gropu in the directory where the python script resides.
5 - Environment: Node-Red 1.0.6 running on Ubuntu 18.04.4 LTS, and started from the browser as URL http://127.0.0.1:1880/

Why is that this happens when, it appears that Node-RED is executing as root (all the reach of root), and also, root is one of the users in the group ac_nodered that has "rwx" in that directory?

Any help will be greatly appreciated. Rgds,Alex

Do you have a good reason for running as root? This is inherently risky as it gives node-red full access to trash your system in the case of a bug, accident or malicious intent.
I would start by fixing that, so it is not running as root (did you see the recommended Debian/Ubuntu/Pi install script?). Then fix the file permissions in your home folder
sudo chown -R alex:alex ~
and start again. This may not fix the problem but may throw light on what is going on.

Hi Colin, thanks for your reply. I don't know why Node-Red is using 'root' user, and it was definitely not my intention. I didn't request that during installation of Node-Red.

How can I change the Ubuntu user that is being used by Node-Red to my user "alex"?

Thanks!

How did you install it and how are you running it?
Also please post the startup log you get when you run it.

Colin, for a clean start, I exported my flows, reinstalled Node-RED in my Ubuntu machine following https://nodered.org/docs/getting-started/raspberrypi, imported flows again, and now everything works properly.
Thank you!

Excellent, glad to be of help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.