arnauorriols / node-red-contrib-python-function

Write Python functions in Node-RED!
MIT License
41 stars 23 forks source link

Python function cannot decode the script #12

Open TejasBajania opened 4 years ago

TejasBajania commented 4 years ago

I have created a node image in python function I have added simple code like: image But I am getting an error like: s = s.decode(detect_encoding(s), 'surrogatepass') File "C:\Users\user\AppData\Local\Continuum\anaconda3\lib\encodings\utf_32_le.py", line 11, in decode return codecs.utf_32_le_decode(input, errors, True) UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 16-19: code point not in range(0x110000)

Can anyone suggest any solution related to this? Like how can we use a python environment in node-red. Also I am using Anaconda environment how can I use it for node-red. I am using windows machine.

lchtbruno commented 3 years ago

having the same issue. The json of my node-red application is pretty simple (check below). All the app does is inject a (json)message ( {"id": "datapoint1", "value": "124.6215", "timestamp": "1601477603842888960" }), the python function should forward it, and the debug node should receive it:

[{"id":"7bc803fa.fe25ac","type":"tab","label":"1","disabled":false,"info":""},{"id":"d3811b80.53c9e8","type":"inject","z":"7bc803fa.fe25ac","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":" { \"id\": \"datapoint1\", \"value\": \"124.6215\", \"timestamp\": \"1601477603842888960\" }","payloadType":"json","x":240,"y":180,"wires":[["de1f02dd.008a9"]]},{"id":"de1f02dd.008a9","type":"python-function","z":"7bc803fa.fe25ac","name":"","func":"\nreturn msg","outputs":1,"x":490,"y":180,"wires":[["2b9229e3.b17286"]]},{"id":"2b9229e3.b17286","type":"debug","z":"7bc803fa.fe25ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":180,"wires":[]}]

xirami commented 3 years ago

We discovered this on Windows, could you potentially share your OS version?

Anyway, on Windows 10 message passed to Python is prepended by 16 bytes. had no time to investigate, ripping out the first 16 bytes worked, however on Windows sending message back is not working.

Andoramb commented 3 years ago

I can also confirm this on Windows 10

Fluxoea commented 1 year ago

Ola, você pode dar um exemplo de como utilizar esse nó, não encontrei nada sobre o mesmo e tentei utilizar de todas as formas sem sucesso

Luky12568 commented 4 months ago

2 years later same issue......

5 May 11:42:00 - [error] [python-function:40137cc40ebc0341] Traceback (most recent call last):
  File "<string>", line 67, in <module>
  File "C:\Python312\Lib\json\__init__.py", line 341, in loads

5 May 11:42:00 - [error] [python-function:40137cc40ebc0341]     s = s.decode(detect_encoding(s), 'surrogatepass')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\encodings\utf_32_le.py", line 11, in decode
    return codecs.utf_32_le_decode(input, errors, True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 16-19: code point not in range(0x110000)
decoding with 'utf-32-le' codec failed

5 May 11:42:00 - [error] [python-function:40137cc40ebc0341] Python Function process exited with code 1
Luky12568 commented 4 months ago

image