# Python script in node red

**URL:** <https://discourse.nodered.org/t/python-script-in-node-red/41164>\
**Category:** General\
**Created:** [17 February 2021 14:38 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164 "2021-02-17T14:38:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [17 February 2021 14:38 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/1 "2021-02-17T14:38:57Z")

</div>

Trying to run a python script from inside node red. Downloaded a couple of nodes but they don't seem to do what I need  
node-red-contrib-pythonshell  
node-red-contrib-python-function  
The script I have runs fine from the command line but needs to start using sudo. I am assuming that the sudo command needs to run from within node red but in these two nodes I have been unable to figure out how to insert the command with sudo. WIthout sudo the command fails but with the sudo command I get a node red error. exit code 1, traceback and a lot more.  
I may be missing the obvious, ok , probably missing the obvious

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 February 2021 15:18 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/2 "2021-02-17T15:18:25Z")

</div>

1. does the user running NR have SUDO privilege?
2. have you tried using the `exec` node?
3. what platform are you running on?

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [17 February 2021 15:22 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/3 "2021-02-17T15:22:30Z")

</div>

the NR user does not have sudo rights. Have not tried the exec node, but will. This is on a Pi 3 running Raspbian with the latest updates to node red.

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [17 February 2021 15:30 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/4 "2021-02-17T15:30:52Z")

</div>

So..... the exec node does work but is there any way to get feedback from the script? I have several print commands that I would like to see that report back to me.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 February 2021 15:32 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/5 "2021-02-17T15:32:36Z")

</div>

Did you put `debug` nodes (set to display the complete msg object) on each of the three outputs of the node to see what you would get.

If you are running on a Pi wth the default 'Pi' user, it should have sudo authority....

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [17 February 2021 15:37 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/6 "2021-02-17T15:37:23Z")

</div>

Did put a debug node on each output, set to complete, nothing on any of them. Yes, running on a Pi with default user so apparently that does have sudo authority.  
[edit]  
but I do get a PID number at the bottom of the node so I am assuming it's running

---

<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 February 2021 15:40 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/7 "2021-02-17T15:40:47Z")

</div>

Look at the options in the Output field in the exec node.

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [17 February 2021 15:48 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/8 "2021-02-17T15:48:21Z")

</div>

tried both options in output with no results from either setting

---

<div class="post-metadata">

**Author:** ![shel](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shel](https://discourse.nodered.org/u/shel)\
**Post date:** [17 February 2021 15:49 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/9 "2021-02-17T15:49:42Z")

</div>

ok, did the stupid thing and didn't deploy after changing the settings. got output now,  
Thanks to all

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 March 2021 15:49 UTC](https://discourse.nodered.org/t/python-script-in-node-red/41164/10 "2021-03-03T15:49:54Z")

</div>

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