[Twisted-Python] question : json.loads failed using LineReceiver data

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon May 14 06:47:17 MDT 2012

On 08:53 am, bino at indoakses-online.com wrote:
>Dear All ..
>I'm trying to received json formated text using LineReceiver
>Here is my code
>class ArduinoReceiver(LineReceiver):
>     def __init__(self):
>         print 'INIT : ArduinoReceiver'
>     def lineReceived(self, line):
>         line = line.strip()
>         print 'Received line = '+line
>         if 'Arduino' in line :
>             return
>         self.linedict=json.loads(line)
>but I got error msg in the log as :
>2012-05-14 15:42:00+0700 [-] Received line =

Read your log message.  This is not a valid JSON string:


Presumably your objective is to receive something like this instead:


The problem is unrelated to Twisted or the console.  The sender is 
sending the wrong data, or else your parsing of it is incorrect.


More information about the Twisted-Python mailing list