[Twisted-Python] question : json.loads failed using LineReceiver data
Dear All .. I'm trying to received json formated text using LineReceiver Here is my code START 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) STOP- but I got error msg in the log as : START 2012-05-14 15:42:00+0700 [-] Received line = '{"a_flw_fwd":12,"a_flw_rtr":5029,"a_rpm":519,"b_flw_fwd":23,"b_flw_rtr":8,"b_rpm":913}' 2012-05-14 15:42:00+0700 [-] Unhandled Error Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/python/log.py", line 84, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/python/log.py", line 69, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/python/context.py", line 118, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/python/context.py", line 81, in callWithContext return func(*args,**kw) --- --- File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/internet/posixbase.py", line 586, in _doReadOrWrite why = selectable.doRead() File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/internet/_posixserialport.py", line 62, in doRead return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived) File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/internet/fdesc.py", line 94, in readFromFD callback(output) File "/usr/local/lib/python2.6/dist-packages/Twisted-11.1.0_r33425-py2.6-linux-i686.egg/twisted/protocols/basic.py", line 564, in dataReceived why = self.lineReceived(line) File "./kapal02.tac", line 48, in lineReceived self.linedict=json.loads(line) File "/usr/lib/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.6/json/decoder.py", line 338, in raw_decode raise ValueError("No JSON object could be decoded") exceptions.ValueError: No JSON object could be decoded STOP- I try to do json.loads based on received msg using python console, and it work : ---START- bino@bino-desktop:/var/log/rabbitmq$ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import json >>> aa='{"a_flw_fwd":12,"a_flw_rtr":5029,"a_rpm":519,"b_flw_fwd":23,"b_flw_rtr":8,"b_rpm":913}' >>> mydict=json.loads(aa) >>> print mydict['a_flw_fwd'] 12 ---STOP-- Kindly please tell me why the 'json.loads' is failed in my tac file while it work in python console. Sincerely -bino- ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] question : json.loads failed using LineReceiver data
On 05/14/2012 04:53 AM, bino oetomo wrote: > Kindly please tell me why the 'json.loads' is failed in my tac file > while it work in python console. > Perhaps the JSON spans more than one line? Printing out the repr() of the lines you're receiving may be informative. ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] question : json.loads failed using LineReceiver data
On 08:53 am, b...@indoakses-online.com wrote: >Dear All .. > >I'm trying to received json formated text using LineReceiver > >Here is my code >START >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) > >STOP- >but I got error msg in the log as : >START >2012-05-14 15:42:00+0700 [-] Received line = >'{"a_flw_fwd":12,"a_flw_rtr":5029,"a_rpm":519,"b_flw_fwd":23,"b_flw_rtr":8,"b_rpm":913}' Read your log message. This is not a valid JSON string: '{"a_flw_fwd":12,"a_flw_rtr":5029,"a_rpm":519,"b_flw_fwd":23,"b_flw_rtr":8,"b_rpm":913}' Presumably your objective is to receive something like this instead: {"a_flw_fwd":12,"a_flw_rtr":5029,"a_rpm":519,"b_flw_fwd":23,"b_flw_rtr":8,"b_rpm":913} The problem is unrelated to Twisted or the console. The sender is sending the wrong data, or else your parsing of it is incorrect. Jean-Paul ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
[Twisted-Python] Cannot install Twisted version 8 through PIP
Hi, We're having some troubles today, because it seems that old packages of Twisted are not available anymore. We are currently relying on Twisted 8.2.0. pip install twisted==8.2.0 is failing (first version available seems to be 9.0.0) The package was still available last Friday. Is there a critical reason explaining that it has been removed from the servers ? Thanks very much, Best regards, -- Pascal BRIET Software engineer Optimor Labs http://www.billmonitor.com ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Cannot install Twisted version 8 through PIP
On 05/14/2012 09:14 AM, Pascal Briet wrote: > Hi, > > We're having some troubles today, because it seems that old packages > of Twisted are not available anymore. > We are currently relying on Twisted 8.2.0. > > pip install twisted==8.2.0 is failing (first version available seems > to be 9.0.0) > The package was still available last Friday. > > Is there a critical reason explaining that it has been removed from > the servers ? > My understanding is that pip uses PyPI, and personally I know of no one who removed stuff from PyPI; more likely PyPI decided to remove old versions of software to save space. Any reason you're using 8.2? It's almost 4 years old at this point, and we've fixed a lot of bugs and added a lot of features since then. -Itamar ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Cannot install Twisted version 8 through PIP
Hi, Thanks for your answer. Well, there is no specific reason that we use the 8.2.0 version. It's just... history. We never needed to upgrade it. Do you think we can easily upgrade to 9/10/11/12 ?? Thanks very much, -- Pascal BRIET Software engineer Optimor Labs http://www.billmonitor.com On 14 May 2012 14:29, Itamar Turner-Trauring wrote: > On 05/14/2012 09:14 AM, Pascal Briet wrote: > > Hi, > > > > We're having some troubles today, because it seems that old packages > > of Twisted are not available anymore. > > We are currently relying on Twisted 8.2.0. > > > > pip install twisted==8.2.0 is failing (first version available seems > > to be 9.0.0) > > The package was still available last Friday. > > > > Is there a critical reason explaining that it has been removed from > > the servers ? > > > My understanding is that pip uses PyPI, and personally I know of no one > who removed stuff from PyPI; more likely PyPI decided to remove old > versions of software to save space. > > Any reason you're using 8.2? It's almost 4 years old at this point, and > we've fixed a lot of bugs and added a lot of features since then. > > -Itamar > > ___ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Cannot install Twisted version 8 through PIP
On 05/14/2012 09:35 AM, Pascal Briet wrote: > Hi, > > Thanks for your answer. > > Well, there is no specific reason that we use the 8.2.0 version. > It's just... history. We never needed to upgrade it. > > Do you think we can easily upgrade to 9/10/11/12 ?? > Thanks very much, > We have a strict backwards compatibility policy; anything that changes or is removed will have deprecation warnings for at least 2 releases and one year. So the thing to do is, upgrade to version 9, run your program and make sure its tests pass, and fix any code that triggers deprecation warnings in Twisted. Repeat with each version until you're up to date. In most cases this may take as little as a couple of hours of work; possibly none if you didn't happen to be using any deprecated APIs. ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Cannot install Twisted version 8 through PIP
Ok, Thanks for your help. Best regards, -- Pascal BRIET Software engineer Optimor Labs http://www.billmonitor.com On 14 May 2012 14:54, Itamar Turner-Trauring wrote: > On 05/14/2012 09:35 AM, Pascal Briet wrote: > > Hi, > > > > Thanks for your answer. > > > > Well, there is no specific reason that we use the 8.2.0 version. > > It's just... history. We never needed to upgrade it. > > > > Do you think we can easily upgrade to 9/10/11/12 ?? > > Thanks very much, > > > > We have a strict backwards compatibility policy; anything that changes > or is removed will have deprecation warnings for at least 2 releases and > one year. > > So the thing to do is, upgrade to version 9, run your program and make > sure its tests pass, and fix any code that triggers deprecation warnings > in Twisted. Repeat with each version until you're up to date. In most > cases this may take as little as a couple of hours of work; possibly > none if you didn't happen to be using any deprecated APIs. > > ___ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python