Can't execute Python script via Node-RED

I'm trying to execute a python script through Node-RED, and while previously it worked, I had to format my Raspberry Pi and now it no longers works.

The errors it outputs is "cannot connect to X server". The script works fine if I execute it in a Raspberry terminal, and when I reinstalled Node-RED I imported my previous flow, so everything is exactly as it was before.

Here is a picture with the exec node configuration.

Is there any configuration on the Raspberry Pi I might have missed out while installing it again or is the problem coming from Node-RED?

Does you script work if you SSH in from another machine and run it there?

Does your script expect there to be a display?

Try using
DISPLAY=:0 python....

If still no joy then show us the full error message. Is that error coming from the error output on the exec node?

From a quick search on internet...

...means that your code is trying (and failing) to connect to an X server -- a GUI environment -- presumably being forwarded over your SSH session.

If you want to stop it from being able to make any GUI connection at all (and perhaps, if the software is thusly written, from even trying), unset the DISPLAY environment variable before running your code.

My script is a QR reader that uses a camera module to scan qr codes in the field of view, the script shows a window that displays the cameras field of view.
Using the "DISPLAY=:0" allows the script to run but it no longer functions as before, previously when it detected a QR code it would output the QR code contents in Node-RED, but using "DISPLAY=:0" it doesn't output the QR code content.

The error comes out of the stderror exec output.

Does your script send it to stdout?

Yeah it does, but I fixed the issue by importing an older version of my flow. Maybe something went wrong when importing since I didn't have everything installed yet.

Thanks for the help!

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