# Exec node & Python

**URL:** <https://discourse.nodered.org/t/exec-node-python/38005>\
**Category:** General\
**Created:** [25 December 2020 12:33 UTC](https://discourse.nodered.org/t/exec-node-python/38005 "2020-12-25T12:33:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefananderssonster](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefananderssonster/32/34040_2.png) [@Stefananderssonster](https://discourse.nodered.org/u/Stefananderssonster)\
**Post date:** [25 December 2020 12:33 UTC](https://discourse.nodered.org/t/exec-node-python/38005/1 "2020-12-25T12:33:21Z")

</div>

Hello, I'm trying to run a python script with the exec node on my RPI4. Running the script from the terminal with: python3 /home/pi/Documents/webscarp.py works just fine but using the same command line in the exec node gives me a code 1 error.

If I try with a simple print hello script the exec node executes the script so I guess it must have something to do with the import selenium part. Maybe I must add something more to the script? Have googled alot for a solution but since Pyhton is a new thing for me I have trouble understanding all the information I find.

webscarp.py  
from selenium import webdriver  
driver = webdriver.Chrome()  
driver.get("[https://gmail.com](https://gmail.com)")

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 December 2020 13:00 UTC](https://discourse.nodered.org/t/exec-node-python/38005/2 "2020-12-25T13:00:11Z")

</div>

A question rather than an answer...

What are you attempting to do? Read emails from Gmail?

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [25 December 2020 17:26 UTC](https://discourse.nodered.org/t/exec-node-python/38005/3 "2020-12-25T17:26:29Z")

</div>

The exec node needs the full path to your executable webscarp.py code, probably /home/yourLoginName/webscarp.py

Webscarp.py needs:  
#!/usr/bin/env python3  
As the first line, and the execute bit must be set on the webscarp.py file.

Or you might try:  
/usr/bin/python3 /home/pi/Documents/webscarp.py

The /home/pi/Documents/webscarp.py might need to be in the "extra command parameters" box in the exec node properties instead of being part of the command. Try it both ways.

---

<div class="post-metadata">

**Author:** ![Stefananderssonster](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefananderssonster/32/34040_2.png) [@Stefananderssonster](https://discourse.nodered.org/u/Stefananderssonster)\
**Post date:** [26 December 2020 10:15 UTC](https://discourse.nodered.org/t/exec-node-python/38005/4 "2020-12-26T10:15:53Z")

</div>

Hi, I want to extract some data from websites and that process needs some web browser actions so I can't use the http request node in this case. The gmail thing is just a starting point for testing. I'm not a programmer soo I tend to start out small and see if it works and if it does make changes and add things on.

I wanted to use a node package called wd2 for this project but I can't get that to work either.  
Some issues with the chrome-webdriver I think.

---

<div class="post-metadata">

**Author:** ![Stefananderssonster](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefananderssonster/32/34040_2.png) [@Stefananderssonster](https://discourse.nodered.org/u/Stefananderssonster)\
**Post date:** [27 December 2020 15:15 UTC](https://discourse.nodered.org/t/exec-node-python/38005/5 "2020-12-27T15:15:06Z")

</div>

I think the exec node starts running the script and then something fails. That is my interpretation of the debug output. But then again I have no experience with python. The best solution for me is if I could get the WD2 red node package to work.

Traceback (most recent call last): File "/home/pi/Documents/webscarp.py", line 7, in   
driver = webdriver.Chrome() File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/chrome/webdriver.py",  
line 81, in **init** desired\_capabilities=desired\_capabilities)  
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py",  
line 157, in **init** self.start\_session(capabilities, browser\_profile)  
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py",  
line 252, in start\_session response = self.execute(Command.NEW\_SESSION, parameters)  
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py",  
line 321, in execute self.error\_handler.check\_response(response)  
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py",  
line 242, in check\_response raise exception\_class(message, screen,  
stacktrace)selenium.common.exceptions.WebDriverException...

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [27 December 2020 15:23 UTC](https://discourse.nodered.org/t/exec-node-python/38005/6 "2020-12-27T15:23:42Z")

</div>

If you are trying to use a node npm package in a node-red function node, your issue is that requires('nodePackageName') doesn't work inside of node-red function nodes.

Change directories to your .node-red directory and npm install your nodejs package.

Next you must edit .node-red/settings.js and add to:  
functionGlobalContext: {  
yourObjectName:require('nodePackageName')  
}

Use the commented out examples in the fuctionGlobalContext{} stanza as an example.

Requires a node-red restart when finished.

Then you can access the function or object with:  
var yourObjectName = global.get('nodePackageName');

This is explained tersely in the docs:

> **[Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions)**

towards the bottom.

---

<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:** [25 February 2021 15:23 UTC](https://discourse.nodered.org/t/exec-node-python/38005/7 "2021-02-25T15:23:44Z")

</div>

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