Closed specked2527 closed 8 months ago
您 Ctrl + C
了
您
Ctrl + C
了
不不,我描述有问题,问题是;程序运行1分钟没有输出,无响应
KeyboardInterrupt 是我手动ctrl+c
的
https://github.com/Nemo2011/bilibili-api/assets/124735279/249ef84e-3919-4364-9f9b-2d25f8dcef7c
虽然但是,建议使用 vscode 等编辑器来调试程序
虽然但是,建议使用 vscode 等编辑器来调试程序
:( 感谢你的回复 vscode debug
PS C:\Users\NAS\BilibiliGetDynamics> & 'c:\Users\NAS\AppData\Local\Programs\Python\Python38\python.exe' 'c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '8225' '--' 'C:\Users\NAS\BilibiliGetDynamics\1.py'
E+00000.093: Error while enumerating installed packages.
Traceback (most recent call last):
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\common\log.py", line 361, in get_environment_description
report(" {0}=={1}\n", pkg.name, pkg.version)
AttributeError: 'PathDistribution' object has no attribute 'name'
Stack where logged:
File "C:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher\__main__.py", line 91, in <module>
main()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher\__main__.py", line 21, in main
log.describe_environment("debugpy.launcher startup environment:")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\common\log.py", line 369, in describe_environment
info("{0}", get_environment_description(header))
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\common\log.py", line 363, in get_environment_description
swallow_exception("Error while enumerating installed packages.")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\common\log.py", line 215, in swallow_exception
_exception(format_string, *args, **kwargs)
E+00000.031: Error while enumerating installed packages.
Traceback (most recent call last):
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 361, in get_environment_description
report(" {0}=={1}\n", pkg.name, pkg.version)
AttributeError: 'PathDistribution' object has no attribute 'name'
Stack where logged:
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 415, in main
api.ensure_logging()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\api.py", line 61, in ensure_logging
log.describe_environment("Initial environment:")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 369, in describe_environment
info("{0}", get_environment_description(header))
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 363, in get_environment_description
swallow_exception("Error while enumerating installed packages.")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 215, in swallow_exception
_exception(format_string, *args, **kwargs)
E+00000.235: Error while enumerating installed packages.
Traceback (most recent call last):
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 361, in get_environment_description
report(" {0}=={1}\n", pkg.name, pkg.version)
AttributeError: 'PathDistribution' object has no attribute 'name'
Stack where logged:
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 281, in run_file
log.describe_environment("Pre-launch environment:")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 369, in describe_environment
info("{0}", get_environment_description(header))
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 363, in get_environment_description
swallow_exception("Error while enumerating installed packages.")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 215, in swallow_exception
_exception(format_string, *args, **kwargs)
手动ctrl+c
后
Traceback (most recent call last):
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\NAS\BilibiliGetDynamics\1.py", line 34, in <module>
sync(main())
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\site-packages\bilibili_api\utils\sync.py", line 33, in sync
return loop.run_until_complete(coroutine)
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 603, in run_until_complete
self.run_forever()
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 570, in run_forever
self._run_once()
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1823, in _run_once
event_list = self._selector.select(timeout)
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\selectors.py", line 314, in _select
r, w, x = select.select(r, w, w, timeout)
KeyboardInterrupt
这问题貌似与模块无关,因为问题出在 .vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64
中,估计是这里面代码的问题
不使用 vscode
的 debug
运行试试
或者安装 importlib-metadata
再试试 debug
或者安装
importlib-metadata
再试试debug
:( 感谢你的回复
python.exe -m pip install --upgrade pip
pip install importlib-metadata
没有解决问题 在vscode
里运行,20秒无输出后ctrl+c
DEBUG
PS C:\Users\NAS\BilibiliGetDynamics> c:; cd 'c:\Users\NAS\BilibiliGetDynamics'; & 'c:\Users\NAS\AppData\Local\Programs\Python\Python38\python.exe' 'c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '13084' '--' 'C:\Users\NAS\BilibiliGetDynamics\1.py'
Traceback (most recent call last):
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\NAS\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\NAS\BilibiliGetDynamics\1.py", line 34, in <module>
sync(main())
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\site-packages\bilibili_api\utils\sync.py", line 33, in sync
return loop.run_until_complete(coroutine)
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 603, in run_until_complete
self.run_forever()
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 570, in run_forever
self._run_once()
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1823, in _run_once
event_list = self._selector.select(timeout)
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "c:\Users\NAS\AppData\Local\Programs\Python\Python38\lib\selectors.py", line 314, in _select
r, w, x = select.select(r, w, w, timeout)
KeyboardInterrupt
https://github.com/Nemo2011/bilibili-api/assets/124735279/dd1e34d0-fe51-491f-be6e-ad95edd1a314
发下程序
好抽象…我一直没电脑,干盯着,最顶上那份示例真的能跑吗?不会一直 while True 吧?
发下程序
我无语了...老哥你是不会打断点的吗?看看返回值啊 三个人在云 dev.jpg
以及B站脑瘫设计 has_more
始终为 1
,所以一直在循环,还得检测下有没有 card
字段
import json
from bilibili_api import user, sync
# 实例化
u = user.User(660303135)
async def main():
# 用于记录下一次起点
offset = 0
# 用于存储所有动态
dynamics = []
# 无限循环,直到 has_more != 1
while True:
# 获取该页动态
page = await u.get_dynamics(offset)
if "cards" in page:
# 若存在 cards 字段(即动态数据),则将该字段列表扩展到 dynamics
dynamics.extend(page["cards"])
else:
break
if page["has_more"] != 1:
# 如果没有更多动态,跳出循环
break
# 设置 offset,用于下一轮循环
offset = page["next_offset"]
# 打印动态数量
print(f"共有 {len(dynamics)} 条动态")
# 入口
sync(main())
Python 版本: 3.8
模块版本: 16.2.0 Name: bilibili-api-python
运行环境: Windows
Google,issue没找到解决方法
报错
运行代码
debug