cyhex / streamcrab

Real-Time, Twitter sentiment analyzer engine
http:/www.streamcrab.com
144 stars 49 forks source link

AttributeError: 'str' object has no attribute 'get' #1

Closed erick-repo closed 12 years ago

erick-repo commented 12 years ago

I have installed all the modules and run all the steps to work with the the SMM and when Im trying to run the client python program to connect to the server the server side dumps this error,

I'm currently stuck on this:

tracker # python moodClassifierd.py debug starting debug mode...

OK

Exception happened during processing of request from ('127.0.0.1', 51861) Traceback (most recent call last): File "/usr/lib/python2.6/SocketServer.py", line 560, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.6/SocketServer.py", line 617, in init self.handle() File "moodClassifierd.py", line 60, in handle raise e

AttributeError: 'str' object has no attribute 'get'

The moodClassifierd.py is throwing an exception on the line 60, do you guys know what it is happening?

try:

        data_to_send = []
        for r in recvData:
            text = r.get('text')
            r['x_lang'] = self.server.langCls.detect(text)[0]
            r['x_mood'] = self.server.moodCls.classify(text,r['x_lang'] )
            data_to_send.append(r)
    except Exception,e:
        raise e                  <------------------------------------------------------------HERE
        return False

    self._send(data_to_send)
cyhex commented 12 years ago

Hi, it looks like you are passing list of strings instead of list of dicts, look at the smm / tracker / tests / moodClientServerTest.py the data should look like this:

python data = [ {'text':'some text 1'}, {'text':'some text 2'}, {'text':'some text N'}, ]

dwmcqueen commented 12 years ago

I tried editing the moodClientServerTest.py with the data you have, and got this error:

Exception happened during processing of request from ('127.0.0.1', 52018) Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 639, in init self.handle() File "moodClassifierd.py", line 60, in handle raise e

Exception: not unicode

erick-repo commented 12 years ago

We found the error it looks like you have to change the lines from 51 /moodClassifierd.py, probably the version of python its not supporting it.

try: data_to_send = [] for r in recvData: r = recvData text = unicode(r.get('text')) r['x_lang'] = self.server.langCls.detect(text)[0] r['x_mood'] = self.server.moodCls.classify(text,r['x_lang'] ) data_to_send.append(r) except Exception,e: raise e

dwmcqueen commented 12 years ago

Not quite fixed - back to original issue. With using sample client (moodClientServerTest.py ) looking like this:

-- coding: utf-8 --

import sys sys.path.append('../../') from tracker.lib.moodClassifierClient import MoodClassifierTCPClient

MCC = MoodClassifierTCPClient('127.0.0.1',6666)

test_data = {'text':'this is a test text'} data = [ {'text':'some text 1'}, {'text':'some text 2'}, {'text':'some text N'}, ] print MCC.classify(data, 'search')

Get this error:

Exception happened during processing of request from ('127.0.0.1', 44980) Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 639, in init self.handle() File "moodClassifierd.py", line 61, in handle raise e

AttributeError: 'list' object has no attribute 'get'

cyhex commented 12 years ago

yes sorry about that, all libs in smm have to get unicodes and not strings, so the payload should be

python data = [ {'text':u'some text 1'}, {'text':u'some text 2'}, {'text':u'some text N'}, ]



I also made the changes in moodClientServerTest.py. Please update moodClientServerTest.py to the newest version and restore the original moodClassifierd.py