# Problem in showing results in python

**URL:** <https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440>\
**Category:** General\
**Created:** [22 March 2020 05:57 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440 "2020-03-22T05:57:06Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 March 2020 13:44 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/21 "2020-03-22T13:44:35Z")

</div>

Also not working with mqtt and modified script???

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 March 2020 14:02 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/22 "2020-03-22T14:02:29Z")

</div>

I think I know what is causing this...

This line in your python script  
` mens=bytes(payload).decode("utf-8",'ignore')`  
is creating a python bytes object

Try this code

```auto
        BOARD.led_on()
        #print("\nReceived: ")
        self.clear_irq_flags(RxDone=1)
        payload = self.read_payload(nocheck=True)
        send_mqtt_message('loramessage', str(payload))
        #print ("Receive: ")
        mens=bytes(payload).decode("utf-8",'ignore')
        mens=mens[2:-2] #to discard \x00\x00 and \x00 at the end
        print(mens)
        send_mqtt_message('loramessage', str(mens))
        BOARD.led_off()

```

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [22 March 2020 14:56 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/23 "2020-03-22T14:56:11Z")

</div>

I'm working on it, but as I am installing and using paho for the first time, it takes some time to solve errors, and the latest one is :

 ![python3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e4becdc8c56d88d6a5a9202dcc4cd42d2ace7eb.jpeg)  
 ![python4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cbd9f633dd9a85255c9444f782ad2bb21377f5c.jpeg)

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [22 March 2020 15:00 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/24 "2020-03-22T15:00:38Z")

</div>

As you also guess, I have used str() lately to solve the problem in pythonshell and daemon,but face no change in answer there !

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 March 2020 17:28 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/25 "2020-03-22T17:28:17Z")

</div>

Sorry, I missed a part in the script, I have updated it now

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 March 2020 18:43 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/26 "2020-03-22T18:43:21Z")

</div>

@tarahi  
I have updated the script further, I believe I have solved it, when I simulate the data it works but you should run it with python3, like "python3 scriptname.py"  
This is because python3 handles bytes/bytearray differently than python2

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [22 March 2020 18:45 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/27 "2020-03-22T18:45:11Z")

</div>

vow !  
excellent !  
It works correctly  
Thanks for your help ❤ ❤ ❤

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [22 March 2020 18:45 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/28 "2020-03-22T18:45:40Z")

</div>

Nice to hear!!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 April 2020 18:53 UTC](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440/29 "2020-04-05T18:53:23Z")

</div>

Closed on 5 April 2020 18:53 UTC

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

[Previous page](https://discourse.nodered.org/t/problem-in-showing-results-in-python/23440.md?page=1)
