Nemo2011 / bilibili-api

哔哩哔哩常用API调用。支持视频、番剧、用户、频道、音频等功能。原仓库地址:https://github.com/MoyuScript/bilibili-api
https://nemo2011.github.io/bilibili-api/
GNU General Public License v3.0
2.23k stars 215 forks source link

[提问] {获取弹幕的时候,现在报错KeyError: 'total'} #814

Open Sukang1002 opened 2 months ago

Sukang1002 commented 2 months ago

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..run_until_complete(self, future) 95 if not f.done(): 96 raise RuntimeError( 97 'Event loop stopped before Future completed.') ---> 98 return f.result()

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 `iterandnext__` 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

shouge commented 4 weeks ago

我本地测试没有问题 我的版本为 16.3.0 对比你的报错信息发现加了关键的判断逻辑 升级版本可以解决