# Exec Node to start Python Script - permission error

**URL:** <https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638>\
**Category:** General\
**Created:** [17 September 2019 20:38 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638 "2019-09-17T20:38:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![GRitchie1](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@GRitchie1](https://discourse.nodered.org/u/GRitchie1)\
**Post date:** [17 September 2019 20:38 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/1 "2019-09-17T20:38:08Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 September 2019 20:53 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/2 "2019-09-17T20:53:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GRitchie1](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@GRitchie1](https://discourse.nodered.org/u/GRitchie1)\
**Post date:** [17 September 2019 20:57 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/3 "2019-09-17T20:57:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 September 2019 21:02 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/4 "2019-09-17T21:02:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GRitchie1](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@GRitchie1](https://discourse.nodered.org/u/GRitchie1)\
**Post date:** [17 September 2019 21:03 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/5 "2019-09-17T21:03:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 September 2019 21:11 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/6 "2019-09-17T21:11:53Z")

</div>

> [@Colin](#):
>
> If you logon as that user in a terminal and then run the python command is it ok?

You haven't answered that question.

> [@Colin](#):
>
> how did you install node-red and how are you running it?

You haven't answered that question either.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [17 September 2019 21:41 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/7 "2019-09-17T21:41:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GRitchie1](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@GRitchie1](https://discourse.nodered.org/u/GRitchie1)\
**Post date:** [18 September 2019 18:28 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/8 "2019-09-18T18:28:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GRitchie1](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@GRitchie1](https://discourse.nodered.org/u/GRitchie1)\
**Post date:** [18 September 2019 19:25 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/9 "2019-09-18T19:25:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 September 2019 20:55 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/10 "2019-09-18T20:55:18Z")

</div>

> [@GRitchie1](#):
>
> I didn't need to install node-red as it is part of the raspbian image.

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](https://nodered.org/docs/getting-started/raspberrypi)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 September 2019 20:59 UTC](https://discourse.nodered.org/t/exec-node-to-start-python-script-permission-error/15638/11 "2019-09-18T20:59:58Z")

</div>

> [@GRitchie1](#):
>
> I managed to fix this. I went into the properties of the file, and set its permissions to Anyone can change it.

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.
