FIle unavailable for Node red - ubuntu

Hello

I'm all new to Node Red and are stuck. I have Homeassistant installed in a Docker on Ubuntu. Have Installed the Node Red Integration. Integration works well. I have a simple flow in Node Red with an exec node that runs a Python script when a sensor changes. Flow is triggered as it should but it fails on the exec node. The Node Red node runs the following script and argument:

python3 ~/home/joern/Documents/flysjekk.py NAX9T

but it fails with the following error messages:

python3: can't open file '/root/home/joern/Documents/flysjekk.py': [Errno 2] No such file or directory

Properties on the flysjekk.py file is as following:
/home/joern/Documents

Running the above command from the terminal works like a charm.

I have very little experience with ubuntu so I hope someone are able and willing to help me through this.
Thanks in advance.

The normal file system is not accessible from a Docker container unless you specifically allow access to the areas you want. That is one of the points of running in a container, the rest of the system is not accessible from the container and therefore cannot be messed up by it. If you do need access from within the container then the first question to ask is why are you running in Docker? Unless you have a good reason it is generally simpler not to run in Docker.

Actually I don't know why it is running in a Docker. It happened when HA ws installed. Node Red was installed via Homeassistant

I think you will have to ask about that on a HA forum.

However, that might be a red herring, looking at your code again.

Are you sure you ran that command from the terminal and not
python3 /home/joern/Documents/flysjekk.py NAX9T

You are right. The command I ran from the terminal was without the ~

Can the ~ be the problem?

Yes, try that from terminal.

Ok. I did a test. This is the command that works in the terminal:
python3 /home/joern/Documents/flysjekk.py NAX9T

with the ~ it fails in the terminal.
I also entered that in the exec node and there it fails witth the same error I have all the time.

What did you enter in the exec node? If you mean that you entered it correctly (that is without the ~) then I don't believe that you get exactly the same error. If you do then show us the config of the exec node and the error.

This is my exec node:

[{"id":"a17ab8e6.92a9b8","type":"exec","z":"50c7f7f0.14c9d8","command":"python3 /home/joern/Documents/flysjekk.py NAX9T","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Test","x":410,"y":160,"wires":[["60143e12.e1caa8"],["5379fd5f.ae0294"],["d638aacb.e748f"]]}]

This is the error I get:

python3: can't open file '/home/joern/Documents/flysjekk.py': [Errno 2] No such file or directory

This is a screenshot when ran from the terminal

Note it is not the same error message.

You have told it to append msg.payload to the command, I suspect that is not what you want. If you don't want that box ticked then clear it. I don't think it will make any difference though. If not then we are back to the fact that it is running in Docker (if node-red is in fact running in docker).

How do you start and stop node red?

The fact that ~ resolved to /root tells that Node-RED is running as the root user. This won't work unless you have specifically created a directory /home/joern/Documents inside the Docker conftainer and added the Python script there. Even if it was, it's not guaranteed the Docker container running Node-RED includes a Python runtime.

Id also suggest asking from the Home Assistant community as this is not really a Node-RED issue but related to it being run inside a container. And in this case the container is set up and started by the Node-RED plugin or the HA runtime.

ok. I got a step further. I also have these python script in another directory under the homeassistant directory. It looks like Node Red is able to finde the python scripts. I changed he path in the exec node to the following:

python3 /config/python_scripts/flysjekk.py NAX9T

That gives me this error:

Traceback (most recent call last): File "/config/flysjekk.py", line 1, in import flightawareparser File "/config/flightawareparser.py", line 6, in import requestsModuleNotFoundError: No module named 'requests'

flysjekk.py looks like this:

import flightawareparser
import sys
state = sys.argv[1]
facheck = flightawareparser.fascrapper()
details = facheck.flightdata(state)
print(details)

The flightawareparser.py starts like this:

from datetime import datetime, timezone
import json
import urllib.request
import requests
import re

As i read the error it means that it fails on the import requests line. Any idea how I can solve that?

I believe that means that the python running in the container does not have the requests module installed.

OK. Folks. I abandoned this and chose another path. Just rant in to many problems.
I solved this with a command line sensor in Home assistant.

Thanks a lot for your input. Even if it didn't solve my problem I appreciate your efforts. Hope I can come back another time with Node Red related problems.

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