Python in Node Red

Hi All

So i want to do some python script inside node red to communicate with a S7 PLC. From Odoo btw.

I have installed the python function node but here are the following error:
image
image

I have a python script which works when i execute it with the pythonshell node but my problem is i want to edit the script with other nodes. like id numbers which it must retrieve from odoo. So if i can get that python function node to work i can write my script in that.

Or what other node is there that i can use to write the script to a file and then use the pythonshell to execute that file?

You might want to review the node's issues in GitHub: Issues · namgk/node-red-contrib-pythonshell · GitHub
espically this one: Not resolving module names · Issue #11 · namgk/node-red-contrib-pythonshell · GitHub

Yeah my pythonshell and exec node works fine when i run a script with it.
My problem is when i use the https://flows.nodered.org/node/node-red-contrib-python-function node that error as shown in the picture pops up.

Use the exec node. You can pass parameters such as the id numbers to your script from msg.payload

That's certainly an interesting issue, but the error shown in the first post, No module named json is striking me as especially odd as this is a builtin module in a default Python installation. It has been present since Python 2.6, if I remember correctly, which was first released in 2008 and has been EOL since 2013. I haven't even seen in it on enterprise systems in a long time. If I had to guess this is because the python-function node first serialises the entire msg object on Node-RED to JSON, then pushes that through an opened file descriptor into the program, so even if you don't use JSON or the JSON module in your project, if the python in your path called can't find those modules you're in trouble.

I've seen similar issues like this with python-function before. The OP is best of using either pythonshell, or an exec node with the script. I personally wouldn't attempt to use the python-function node, if you remember correctly (it has popped up on the forums before), it comes with this usage instruction:

1 Like

If you don't mind me asking, why don't you use the S7 nodes and skip python altogether?

Or is it something else you are doing in python to communicate with the PLC?

I only ask because it is quite possible what you are trying to do may be already perfectly possible in node-red and therefore avoid the need to shell python altogether.

1 Like

The problem is i need to send some info from odoo.com to the PLC and therefore i need to write a python script. Because the odoo nodes needs git installed and i cant find to do it correctly on the IOT2000...

But i found a way to send parameters into the python script which will help alot. Just need some more examples how to use that parameters.

It looks like the odoo nodes depend on a repository directly from git (meaning you need git installed to install the odoo nodes)

Personally, I would raise an issue on the repository.

However, this is not a show stopper. It is possible to download the node from a pc and copy it over.

Yeah i have tried it now. Dont know why i havent thought of it because that is actually how i install nodes and not through the cmd anymore..

But then this is the next error i get. Think its because i didnt install it the proper way.
image

That particular node is the dependency I was talking about.

You can simply npm install that on a different pc, then copy that too

E.g (windows)...

cmd
mkdir deps
npm init (say yes/next to everything)
npm install odoo-xmlrpc

Then you will find all the dependencies in deps\node_modules. You can copy them over and restart node-red

Okay have tried it now but does not work.. but thank you. Im just going to use the pythonshell and input some parameters. I was wondering if you could help me with the following.

When there is a confirmation somewhere in this string I want to retrieve the ID of that confirmation everytime i retrieve that string shown in the pic below:
image

so how would i wrote a function node after the pythonshell to retrieve ID 8 because its confirmed.

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