Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python function cannot decode the script #12

Open
TejasBajania opened this issue Jun 15, 2020 · 6 comments
Open

Python function cannot decode the script #12

TejasBajania opened this issue Jun 15, 2020 · 6 comments

Comments

@TejasBajania
Copy link

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
Copy link

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
Copy link

xirami commented Jan 11, 2021

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
Copy link

I can also confirm this on Windows 10

@Fluxoea
Copy link

Fluxoea commented Oct 18, 2022

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
Copy link

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
Copy link

image

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

No branches or pull requests

6 participants