如何处理socketIO-client中收到的数据包中的数据?

时间:2019-06-23 13:02:52

标签: python

我是Python的新手,所以也许我的问题很幼稚,但是我还没有找到解决方案。 我启动了套接字IO_client并从服务器接收数据包,这可以在日志中看到。但是我根本不了解如何解析和使用除日志之外的程序包中的数据。当然,可以解析日志文件,但是必须有更正确的方法。我将不胜感激。


logging.basicConfig(filename='example.log', filemode='w', level=logging.DEBUG)

try:
    s = socketIO_client.SocketIO('https://streamer.cryptocompare.com')
    s.emit('SubAdd', {'subs': ['0~Kraken~BTC~USD']})
    s.wait()


except ConnectionError:
    print('The server is down. Try again later.')

接收日志的数据包:

DEBUG:socketIO-client:streamer.cryptocompare.com:443/socket.io [socket.io packet received] b'2["m","0~Kraken~BTC~USD~2~1561294637.4812~1561294637~0.02637883~10675.8~281.615113314~1561294647~3f"]'

1 个答案:

答案 0 :(得分:0)

这真的很容易) 例如,只是

socketIO.on('m', lambda m: print(m))