Exec node & Python

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.

from selenium import webdriver
driver = webdriver.Chrome()

A question rather than an answer...

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

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.

1 Like

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.

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,

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: {

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:

towards the bottom.

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