[提问] {获取弹幕的时候,现在报错KeyError: 'total'}
Python 版本: 3.12
模块版本: x.y.z
运行环境: Linux
这个还在维护嘛
这是我的代码
获取rank排行 实时查询查询在线观看人数 收集弹幕
import asyncio from bilibili_api import video
实例化
v = video.Video(bvid="BV15EtgeUEaD")
获取在线人数
print(sync(v.get_online()))
print(sync(v.get_danmakus())) #此处会报错
KeyError Traceback (most recent call last) Cell In[43], line 10 7 # 获取在线人数 8 print(sync(v.get_online())) ---> 10 print(sync(v.get_danmakus()))
File ~/anaconda3/lib/python3.12/site-packages/bilibili_api/utils/sync.py:33, in sync(coroutine) 31 __ensure_event_loop() 32 loop = asyncio.get_event_loop() ---> 33 return loop.run_until_complete(coroutine)
File ~/anaconda3/lib/python3.12/site-packages/nest_asyncio.py:98, in _patch_loop.
File ~/anaconda3/lib/python3.12/asyncio/futures.py:203, in Future.result(self) 201 self.__log_traceback = False 202 if self._exception is not None: --> 203 raise self._exception.with_traceback(self._exception_tb) 204 return self._result
File ~/anaconda3/lib/python3.12/asyncio/tasks.py:314, in Task.__step_run_and_handle_result(failed resolving arguments)
310 try:
311 if exc is None:
312 # We use the send method directly, because coroutines
313 # don't have __iter__ and __next__ methods.
--> 314 result = coro.send(None)
315 else:
316 result = coro.throw(exc)
File ~/anaconda3/lib/python3.12/site-packages/bilibili_api/video.py:883, in Video.get_danmakus(self, page_index, date, cid, from_seg, to_seg) 881 if to_seg == None: 882 view = await self.get_danmaku_view(cid=cid) --> 883 to_seg = view["dm_seg"]["total"] - 1 885 danmakus = [] 887 for seg in range(from_seg, to_seg + 1):
KeyError: 'total' Selection deleted
我本地测试没有问题 我的版本为 16.3.0 对比你的报错信息发现加了关键的判断逻辑 升级版本可以解决