mahendrakalkura/diffusion

How to solve this?

Opened this issue · 11 comments

I get this error. Do you have any clue?

2018-03-10T21:01:01+0000 Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 208, in doRead
    return self._dataReceived(data)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 214, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 330, in dataReceived
    self._flushReceiveBIO()
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 295, in _flushReceiveBIO
    ProtocolWrapper.dataReceived(self, bytes)
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/policies.py", line 120, in dataReceived
    self.wrappedProtocol.dataReceived(data)
  File "/usr/local/lib/python2.7/dist-packages/autobahn/twisted/websocket.py", line 131, in dataReceived
    self._dataReceived(data)
  File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 1175, in _dataReceived
    self.consumeData()
  File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 1187, in consumeData
    while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
  File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 1553, in processData
    fr = self.onFrameEnd()
  File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 1674, in onFrameEnd
    self._onMessageEnd()
  File "/usr/local/lib/python2.7/dist-packages/autobahn/twisted/websocket.py", line 159, in _onMessageEnd
    self.onMessageEnd()
  File "/usr/local/lib/python2.7/dist-packages/autobahn/websocket/protocol.py", line 627, in onMessageEnd
    self._onMessage(payload, self.message_is_binary)
  File "/usr/local/lib/python2.7/dist-packages/autobahn/twisted/websocket.py", line 162, in _onMessage
    self.onMessage(payload, isBinary)
  File "/root/diffusion/modules/diffusion.py", line 208, in onMessage
    self.factory.message_handler.post_message(DiffusionMessage(type, topic, body, headers))
  File "/root/diffusion/modules/diffusion.py", line 112, in post_message
    log.msg('received message: %s' % diffusion_message)
  File "/root/diffusion/modules/diffusion.py", line 143, in __str__
    return unicode(self).encode('ascii', 'replace')
exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 87234: ordinal not in range(128)

Are you able to reproduce this error consistently?

@NikosVlagoidis try removing this mehod from DiffusionMessage class. Finally, use Python 2.

Something happend with ascii encodeing.

I replaced this code

    def __repr__(self):
        return '{}({}, {}, {}, {})'.format(self.__class__.__name__, self.type, self.topic, self.body, self.headers)

    def __str__(self):
        try:
            return unicode(self).encode('ascii', 'replace')
        except:
            resp = [self.body]
            return '~~~'.join(str(s) for s in resp)

    def __unicode__(self):
        return '{} {} {} {}'.format(self.type, self.topic, self.body, self.headers)

I saw the other closed issue that you had the js code to parse the data from the websocket. Where did you found it? Do you have any lib or module to parse data in python?

Where did you found it?

I found it on their website.

Do you have any lib or module to parse data in python?

No, nothing outside this library. It was planned as a low level interface, nothing more.

I see they have an iframe with betslip.js but it is different than yours. fewer lines. And I cannot figure out how to parse the data.

Bet365 or William Hill?

bet 365.

I see they have an iframe with betslip.js but it is different than yours.

You have to undo their minification. You can use this tool: http://jsnice.org/

the minified is not actually the problem. I found that mine is 12k lines of code. Can you explain the process of decoding the data using this javascript file? Should I use node? The file seems huge and since I am not familiar with JS I can't figure it out.

The file seems huge and since I am not familiar with JS I can't figure it out.

I can't help you in this case. I just read through it and extracted whatever I wanted.