Closed JO-WTF closed 8 years ago
这肯定也是服务器的锅,不过难道手动拼接的json?醉了
@hanbang-wang @JO-WTF 这里是我的用的库的源码 http://docs.ros.org/fuerte/api/rosbridge_library/html/ultrajsondec_8c_source.html,有抛出的规则
import ujson
a = '"'
ujson.loads(a)
所以这个问题里获得的内容输出的 是 中文 双引号
如果我用原生的 python json 抛出是
ValueError: end is out of bounds
Refer 这个问题的回答:http://stackoverflow.com/questions/37445874/json-error-end-is-out-of-bounds
我觉得是不是 b站服务器对这种弹幕处理策略不同,或者 给的json格式分了段,或者 是没有用json处理。 这个需要进行测试。
这个问题还是开一下吧,我好久没用这个解析弹幕了,所以估计内容格式有些处理不一样,不过临时解决可以加一层try...except
@OctavianLee 这个真心是服务器的问题,你找个弹幕多的直播间,把每一个接收回来的json打印出来,会发现收着收着json就落了一半,后半段直接消失,然后程序就throw了个错误。
@hanbang-wang 要不这样吧,加try...except 要么丢弃 要么 答应这个数据
请问下,这个是怎么解决的呢
Traceback (most recent call last): File "main.py", line 6, in
hime = DanmakuHime()
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/hime.py", line 19, in init
self.run()
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/hime.py", line 39, in run
self.create_service(option, room_id)
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/hime.py", line 57, in create_service
service.cmd_run()
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/services/reciever.py", line 18, in cmd_run
run_recieve(self.room_id)
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/cores/socket_process.py", line 69, in run_recieve
produce_danmaku.switch(sock, danmaku_queue, True)
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/cores/produce_and_consume.py", line 49, in produce_danmaku
status = process_recieve_data(sock, danmaku_queue, data)
File "/Users/JOE/Downloads/Barrage-master-2/danmaku/cores/danmaku_process.py", line 40, in process_recieve_data
msg = ujson.loads(data)
ValueError: Unmatched ''"' when when decoding 'string'
目测是有人发了引号导致的。