订阅“B站”内容报错
Opened this issue · 20 comments
环境
- nonebot-bison 版本:0.9.2
- nonebot 版本:2.3
- 安装方式:
通过 nb-cli 安装 - 操作系统:Windows 11
问题
日志
07-30 23:08:19 [WARNING] nonebot_bison | API request record: https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=2*****&offset=0&need_top=0 Headers({'host': 'api.vc.bilibili.com', 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'connection': 'keep-alive', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', 'cookie': 'LIVE_BUVID=AUTO8217223496945151; b_nut=1722349694; buvid3=05B68736-81DB-92D8-B92A-D96C01599B5A94233infoc'}) | [429] Headers({'date': 'Tue, 30 Jul 2024 15:08:20 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '23', 'connection': 'keep-alive', 'bili-status-code': '-509', 'x-bili-retry-after': '3', 'x-ticket-status': '1'}) {"code":0,"message":""}
07-30 23:08:19 [ERROR] apscheduler | Job "Scheduler.exec_fetch (trigger: interval[0:00:10], next run at: 2024-07-30 23:08:29 CST)" raised an exception
Traceback (most recent call last):
File "<string>", line 21, in <module>
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot\__init__.py", line 335, in run
get_driver().run(*args, **kwargs)
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 186, in run
uvicorn.run(
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\uvicorn\main.py", line 577, in run
server.run()
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\uvicorn\server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 636, in run_until_complete
self.run_forever()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 603, in run_forever
self._run_once()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 1909, in _run_once
handle._run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\asyncio\events.py", line
80, in _run
self._context.run(self._callback, *self._args)
> File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\apscheduler\executors\base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot_bison\scheduler\scheduler.py", line 107, in exec_fetch
to_send = await platform_obj.do_fetch_new_post(SubUnit(schedulable.target, send_userinfo_list))
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot_bison\platform\platform.py", line 109, in do_fetch_new_post
return await catch_network_error(self.fetch_new_post, sub_unit) or []
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot_bison\platform\platform.py", line 53, in catch_network_error
return await func(*args, **kwargs)
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot_bison\platform\platform.py", line 340, in fetch_new_post
post_list = await self.get_sub_list(sub_unit.sub_target)
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\nonebot_bison\platform\bilibili.py", line 203, in get_sub_list
res.raise_for_status()
File "E:\MCL\nonebot\nb04-bot\nb04-bot\.venv\lib\site-packages\httpx\_models.py", line 761, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: ("Client error '429 Too Many Requests' for url 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=2******&offset=0&need_top=0'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429", ['https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=2******&offset=0&need_top=0 Headers({\'host\': \'api.vc.bilibili.com\', \'accept\': \'*/*\', \'accept-encoding\': \'gzip, deflate\', \'connection\': \'keep-alive\', \'user-agent\': \'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\', \'cookie\': \'LIVE_BUVID=AUTO8217223496945151; b_nut=1722349694; buvid3=05B68736-81DB-92D8-B92A-D96C01599B5A94233infoc\'}) | [429] Headers({\'date\': \'Tue, 30 Jul 2024 15:08:20 GMT\', \'content-type\': \'application/json; charset=utf-8\', \'content-length\': \'23\', \'connection\': \'keep-alive\', \'bili-status-code\': \'-509\', \'x-bili-retry-after\': \'3\', \'x-ticket-status\': \'1\'}) {"code":0,"message":""}'])
- 我搜索过了 issue,但是并没有发现过与我类似的问题
- 我确认在日志中去掉了敏感信息
我尝试过更改IP,问题依旧
B站平台还在修复中,如果想使用可以选择正在pr的 #573 中的分支
我等完成修复的正式版吧
感谢解答
我等完成修复的正式版吧
功能是完全的,还在改动的主要是代码结构和逻辑,基本不会有功能上的差别,用的话基本没问题(已经测试很久了
已经发版了 可以试试最新的 v0.9.3
我也遇见了同样的问题,我的操作系统是ubuntu,这是我的错误日志
08-18 03:55:42 [ERROR] apscheduler | Job "Scheduler.exec_fetch (trigger: interval[0:00:10], next run at: 2024-08-18 11:55:52 CST)" raised an exception
Traceback (most recent call last):
File "/root/nb/nvpuji/bot.py", line 11, in <module>
nonebot.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 335, in run
get_driver().run(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 186, in run
uvicorn.run(
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/main.py", line 577, in run
server.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
> File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/scheduler/scheduler.py", line 107, in exec_fetch
to_send = await platform_obj.do_fetch_new_post(SubUnit(schedulable.target, send_userinfo_list))
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 109, in do_fetch_new_post
return await catch_network_error(self.fetch_new_post, sub_unit) or []
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 53, in catch_network_error
return await func(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 340, in fetch_new_post
post_list = await self.get_sub_list(sub_unit.sub_target)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/bilibili.py", line 203, in get_sub_list
res.raise_for_status()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/httpx/_models.py", line 749, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
我也遇见了同样的问题,我的操作系统是ubuntu,这是我的错误日志
下面是不是还有一段
是的,这是完整的
08-18 04:03:21 [ERROR] apscheduler | Job "Scheduler.exec_fetch (trigger: interval[0:00:10], next run at: 2024-08-18 12:03:30 CST)" raised an exception
Traceback (most recent call last):
File "/root/nb/nvpuji/bot.py", line 11, in <module>
nonebot.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 335, in run
get_driver().run(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 186, in run
uvicorn.run(
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/main.py", line 577, in run
server.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
> File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/scheduler/scheduler.py", line 107, in exec_fetch
to_send = await platform_obj.do_fetch_new_post(SubUnit(schedulable.target, send_userinfo_list))
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 109, in do_fetch_new_post
return await catch_network_error(self.fetch_new_post, sub_unit) or []
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 53, in catch_network_error
return await func(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 340, in fetch_new_post
post_list = await self.get_sub_list(sub_unit.sub_target)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/bilibili.py", line 203, in get_sub_list
res.raise_for_status()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/httpx/_models.py", line 749, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: ("Client error '429 Too Many Requests' for url 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=472283747&offset=0&need_top=0'\nFor more information check: https://httpstatuses.com/429", ['https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=472283747&offset=0&need_top=0 Headers({\'host\': \'api.vc.bilibili.com\', \'accept\': \'*/*\', \'accept-encoding\': \'gzip, deflate\', \'connection\': \'keep-alive\', \'user-agent\': \'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\', \'cookie\': \'b_nut=1723953631; buvid3=36BD4E96-20C7-2AFF-D6C2-09F5EE3479F731564infoc\'}) | [429] Headers({\'date\': \'Sun, 18 Aug 2024 04:03:21 GMT\', \'content-type\': \'application/json; charset=utf-8\', \'content-length\': \'23\', \'connection\': \'keep-alive\', \'bili-status-code\': \'-509\', \'x-bili-retry-after\': \'3\', \'x-ticket-status\': \'1\'}) {"code":0,"message":""}'])
应该使用
```log
```
来包裹你的日志部分(
httpx.HTTPStatusError: ("Client error '429 Too Many Requests' for url 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=472283747&offset=0&need_top=0'\n
日志显示这是旧版本的B站 api,建议更新到最新版
还有就是最新版的B站调度间隔是50s,如果想更加稳妥可以手动调整为60s(改源码
具体路径在 nonebot_bison/platform/bilibili/scheduler.py
下的
class BilibiliSite(Site):
name = "bilibili.com"
schedule_setting = {"seconds": 50} # <- 这里
schedule_type = "interval"
client_mgr = BilibiliClientManager
require_browser = True
同时这个问题(50s调度)会在下一个版本调整
我执行了 nb plugin update nonebot-bison出现新的这个错误:
08-18 04:34:57 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_bison.sub_manager, lineno=19) failed.
Traceback (most recent call last):
File "/root/nb/nvpuji/bot.py", line 11, in <module>
nonebot.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 335, in run
get_driver().run(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 186, in run
uvicorn.run(
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/main.py", line 577, in run
server.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/message.py", line 476, in check_and_run_matcher
await _run_matcher(
> File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/message.py", line 428, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 850, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 825, in simple_run
await handler(
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/dependencies/__init__.py", line 94, in __call__
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/sub_manager/add_sub.py", line 84, in got_id
name = await check_sub_target(state["platform"], raw_id_text)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/apis.py", line 9, in check_sub_target
scheduler = scheduler_dict[scheduler_conf_class]
KeyError: <class 'nonebot_bison.platform.bilibili.scheduler.BilibiliSite'>
启用一下 BISON_USE_BROWSER配置项
启用了然后就出现这样
08-18 04:41:16 [ERROR] nonebot_bison | API 352 错误
08-18 04:41:16 [DEBUG] nonebot_bison | <retry state REFRESH> -> <retry state REFRESH>, by <retry event REQUEST_AND_RAISE>
08-18 04:41:17 [DEBUG] nonebot_bison | 刷新B站客户端的cookie
08-18 04:41:17 [WARNING] nonebot_bison | 当前刷新次数: 2/3
08-18 04:42:06 [ERROR] nonebot_bison | API 352 错误
08-18 04:42:06 [DEBUG] nonebot_bison | <retry state REFRESH> -> <retry state REFRESH>, by <retry event REQUEST_AND_RAISE>
08-18 04:42:08 [DEBUG] nonebot_bison | 刷新B站客户端的cookie
08-18 04:42:08 [WARNING] nonebot_bison | 当前刷新次数: 3/3
08-18 04:42:56 [ERROR] nonebot_bison | API 352 错误
08-18 04:42:56 [WARNING] nonebot_bison | 当前已回避次数: 1/3, 本次回避时间至 2024-08-18 04:47:56.193956
正常的,这是目前规避风控的策略。 B站现在就是这么严格,如果可以的话先停止蹲B站几个小时再重新启动(可以不那么快进到风控策略里
哦哦,好的,清楚了,那问题解决了,谢谢
现在过了一周了,好像b站订阅有了新的问题
nonebot_bison.platform.bilibili.retry.ApiCode352Error: api https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?host_mid=12747547&timezone_offset=-480&offset= error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/nb/nvpuji/bot.py", line 11, in <module>
nonebot.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/__init__.py", line 335, in run
get_driver().run(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 186, in run
uvicorn.run(
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/main.py", line 577, in run
server.run()
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
> File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/scheduler/scheduler.py", line 109, in exec_fetch
to_send = await platform_obj.do_fetch_new_post(SubUnit(schedulable.target, send_userinfo_list))
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 108, in do_fetch_new_post
return await catch_network_error(self.fetch_new_post, sub_unit) or []
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 53, in catch_network_error
return await func(*args, **kwargs)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/platform.py", line 342, in fetch_new_post
post_list = await self.get_sub_list(sub_unit.sub_target)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/bilibili/retry.py", line 241, in wrapper
await _retry_fsm.emit(RetryEvent.REQUEST_AND_RAISE)
File "/root/nb/nvpuji/.venv/lib/python3.10/site-packages/nonebot_bison/platform/bilibili/fsm.py", line 159, in emit
return await self.machine.asend(event)
StopAsyncIteration: ['https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?host_mid=12747547&timezone_offset=-480&offset= Headers({\'host\': \'api.bilibili.com\', \'accept\': \'*/*\', \'accept-encoding\': \'gzip, deflate\', \'connection\': \'keep-alive\', \'user-agent\': \'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\', \'cookie\': \'_uuid=2F210531F-6278-D121-5812-81DC41C684EC81657infoc; b_lsid=815A5743_1917290DB4C; b_nut=1724203980; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQ0NjMxMzIsImlhdCI6MTcyNDIwMzg3MiwicGx0IjotMX0._iHa3YobEhdgRClcpH-IHRywsxhEkrUQOqkFHzE3rOg; bili_ticket_expires=1724463072; buvid3=71E0E3E1-6B8F-914C-90E6-17FBA6859DA880983infoc; buvid4=70236351-D313-66B4-3664-87136B9C87FD81943-024082101-rtthW/1PQN2tjbeSWfGvmg%3D%3D; buvid_fp=aba25cec935cdd2cdd3f862a3a2d8ef0\'}) | [200] Headers({\'date\': \'Mon, 26 Aug 2024 07:49:40 GMT\', \'content-type\': \'application/json; charset=utf-8\', \'content-length\': \'39\', \'connection\': \'keep-alive\', \'bili-status-code\': \'-352\', \'x-bili-gaia-vvoucher\': \'voucher_cd206756-4a3f-48e7-bf30-4de877dfefc4\', \'x-rid-result\': \'2\', \'x-ticket-status\': \'1\', \'expires\': \'Mon, 26 Aug 2024 07:49:39 GMT\', \'cache-control\': \'no-cache\', \'x-cache-webcdn\': \'BYPASS from blzone01\'}) {"code":-352,"message":"-352","ttl":1}\n']
这段时间尝试了很多回,包括更换设备 更换 IP 等,依然是请求一次后就直接 api 352
可能这就是非登录cookies的结局(
可能这就是非登录cookies的结局(
所以为什么不搞cookies登录以减少风控呢)
我在最新版本还是遇到了频繁429错误