node-red-contrib-python-function icon indicating copy to clipboard operation
node-red-contrib-python-function copied to clipboard

Python function cannot decode the script

Open TejasBajania opened this issue 4 years ago • 6 comments

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.

TejasBajania avatar Jun 15 '20 06:06 TejasBajania

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":[]}]

lchtbruno avatar Sep 30 '20 16:09 lchtbruno

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.

xirami avatar Jan 11 '21 11:01 xirami

I can also confirm this on Windows 10

Andoramb avatar Jan 18 '21 15:01 Andoramb

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

Fluxoea avatar Oct 18 '22 13:10 Fluxoea

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 avatar May 05 '24 09:05 Luky12568

image

Luky12568 avatar May 05 '24 09:05 Luky12568