Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sukang1002 opened this issue Sep 18, 2024 · 1 comment
Open
Labels
question 这啥呀这是,我不到啊

Comments

@Sukang1002
Copy link

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 __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

@Sukang1002 Sukang1002 added the question 这啥呀这是,我不到啊 label Sep 18, 2024
@shouge
Copy link

shouge commented Oct 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question 这啥呀这是,我不到啊
Projects
None yet
Development

No branches or pull requests

2 participants