Skip to content

Pass Node-RED message to Python script#6

Merged
404background merged 4 commits into404background:mainfrom
Alkarex:pass-message
Jun 20, 2024
Merged

Pass Node-RED message to Python script#6
404background merged 4 commits into404background:mainfrom
Alkarex:pass-message

Conversation

@Alkarex
Copy link
Contributor

@Alkarex Alkarex commented Jun 17, 2024

Allow something like print(msg['payload'])
fix #4
image

@Alkarex Alkarex mentioned this pull request Jun 17, 2024
@404background
Copy link
Owner

Thank you @Alkarex !
I read your code. I think it is a good idea to use python exec to read the msg.payload value.

I installed the repository you Forked into Node-RED and got some errors.
The first error was a missing python file error, which was caused by the missing tmp folder.
This was my mistake, I have fixed this with a .gitignore.
image

The second error was a syntax error when executing the command.
Have you encountered this error?
image copy 3

I will try to solve this error and write the Python code that was written in the command in the new file.

@Alkarex
Copy link
Contributor Author

Alkarex commented Jun 18, 2024

Ah, this is probably due to running on Windows.
Let me try something

@Alkarex
Copy link
Contributor Author

Alkarex commented Jun 18, 2024

Please try again

@404background
Copy link
Owner

Thank you @Alkarex !
I had the same error after that, but it was solved.

I tried it with a short command.
It seems that the error occurs depending on the type of quotation:

image

I fixed it for line 19 in the node/venv.js file.:

const command = `${pythonPath} -c 'import base64;import json;msg=json.loads(base64.b64decode(r"${message}"));exec(open(r"${filePath}").read())'`

const command = `${pythonPath} -c "import base64;import json;msg=json.loads(base64.b64decode(r'${message}'));exec(open(r'${filePath}').read())"`

I can run it in my environment.
Could you try it?

@Alkarex
Copy link
Contributor Author

Alkarex commented Jun 19, 2024

Could you show the error message you get in Node-RED when running with the original quotes?

@404background
Copy link
Owner

@Alkarex
It was the same as the second error message when running with the original quotes.

image

After fixing the quotations, I was able to run it!

image

@Alkarex
Copy link
Contributor Author

Alkarex commented Jun 20, 2024

Your suggestion also works for me, so fine

@404background
Copy link
Owner

Thank you @Alkarex !
I will merge this pull request, and release as a new version.

@404background 404background merged commit db4c419 into 404background:main Jun 20, 2024
@Alkarex Alkarex deleted the pass-message branch June 20, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

input for venv node

2 participants