Nemo2011 / bilibili-api

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

【漏洞】直播视频流获取失败 #379

Closed USN484259 closed 1 year ago

USN484259 commented 1 year ago

Python 版本: 3.8.10

模块版本: 15.5.1

运行环境: Ubuntu 20.04, Linux 5.15.0-76-generic x86_64

模块路径: bilibili_api.live

解释器: cpython

报错信息:

2023-07-06 22:54:22,449 asyncio DEBUG   Using selector: EpollSelector
2023-07-06 22:54:22,450 httpx   DEBUG   load_ssl_context verify=True cert=None trust_env=True http2=False
2023-07-06 22:54:22,451 httpx   DEBUG   load_verify_locations cafile='/home/usn484259/.local/lib/python3.8/site-packages/certifi/cacert.pem'
2023-07-06 22:54:22,802 httpx   INFO    HTTP Request: GET https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=21919321&platform=web&qn=10000&https_url_req=1&ptype=16 "HTTP/1.1 200 OK"
Traceback (most recent call last):
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/utils/network_httpx.py", line 445, in wrapper
    return await func(*args, **kwargs)
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/utils/network_httpx.py", line 510, in request
    if api.method != "GET" and not api.no_csrf:
AttributeError: 'str' object has no attribute 'method'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./live_test.py", line 15, in <module>
    info = sync(room.get_room_play_url())
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/utils/sync.py", line 33, in sync
    return loop.run_until_complete(coroutine)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/live.py", line 383, in get_room_play_url
    return await request(
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/utils/network_httpx.py", line 471, in inner
    return await func(*args, **kwargs)
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/utils/network_httpx.py", line 447, in wrapper
    return await request_old(*args, **kwargs)
  File "/home/usn484259/.local/lib/python3.8/site-packages/bilibili_api/utils/network_httpx.py", line 399, in request_old
    raise ResponseCodeException(code, msg, resp_data)
bilibili_api.exceptions.ResponseCodeException.ResponseCodeException: 接口返回错误代码:19001012,信息:调用bvc-play-url-one出错。
{'code': 19001012, 'message': '调用bvc-play-url-one出错', 'ttl': 1, 'data': {'current_qn': 0, 'quality_description': None, 'durl': None, 'is_dash_auto': False}}

报错代码:

#!/usr/bin/env python3

import logging
from bilibili_api import live, sync

logging.basicConfig(level = 0, format = "%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s")
logger = logging.getLogger(__name__)

agent = {
    "User-Agent": "Mozilla/5.0",
    "Referer": "https://www.bilibili.com/"
}

room = live.LiveRoom(21919321)
info = sync(room.get_room_play_url())
url = info.get("durl")[0].get("url")
logger.info(url)

async def record(url):
    sess = bilibili_api.get_session()
    async with sess.stream("GET", url, headers = util.agent) as resp:
        logger.debug(resp)
        resp.raise_for_status()

        async for chunk in resp.aiter_bytes():
            print('*')

live模块获取视频流地址时抛出异常“调用bvc-play-url-one出错” 在7月6日首次观察到该问题。通过本地录播脚本log确认,只有特定直播间(直播内容)会产生该问题,问题出现时为虚拟主播打Apex 问题发生时直播弹幕中有讨论“虚拟Apex”分区“有直播延时”,“不能录播”等话题

怀疑是B站接口策略改动

USN484259 commented 1 year ago

坏,示例代码忘记sync(record(url))了,不过应该是在get_room_play_url里出的问题

Drelf2018 commented 1 year ago

错误能复现吗,比如另一个打apex的主播也报错

USN484259 commented 1 year ago

在network_httpx.py的request函数中print(resp.text),样例如下:

{"code":19001012,"message":"调用bvc-play-url-one出错","ttl":1,"data":{"current_qn":0,"quality_description":null,"durl":null,"is_dash_auto":false}}

经过试验,在LiveRoom构造时传入Credential不能解决问题 另外可能没表述清楚,我使用bilibili-api-python 15.4.4,在7月6日首次发现该问题,发生问题时其他直播间录制正常。升级到15.5.1后问题仍然存在。

USN484259 commented 1 year ago

错误能复现吗,比如另一个打apex的主播也报错

我去找找试试。另外这个直播间现在还在播,方便的话可以直接debug

USN484259 commented 1 year ago

错误能复现吗,比如另一个打apex的主播也报错

尝试多个Apex区直播间和虚拟区直播间。Apex区均复现该问题,虚拟区无该问题。因此怀疑是Apex分区直播间有特殊机制

jhzgjhzg commented 1 year ago

错误能复现吗,比如另一个打apex的主播也报错

尝试多个Apex区直播间和虚拟区直播间。Apex区均复现该问题,虚拟区无该问题。因此怀疑是Apex分区直播间有特殊机制

虚拟主播主区下有个新子区是虚拟APEX,是在这个分区出现问题吗

USN484259 commented 1 year ago

错误能复现吗,比如另一个打apex的主播也报错

尝试多个Apex区直播间和虚拟区直播间。Apex区均复现该问题,虚拟区无该问题。因此怀疑是Apex分区直播间有特殊机制

虚拟主播主区下有个新子区是虚拟APEX,是在这个分区出现问题吗

在分区 网游:APEX英雄虚拟主播:虚拟APEX 下都存在该问题

Drelf2018 commented 1 year ago

这个我看了下,ow和apex都有这个问题,理由是防炸弹人,但有人推测是给瓦让流量。

再说这也不算是本库的漏洞吧,接口不返回数据不能说是库有问题吧。

zerowuxian commented 1 year ago

可能是apex相关新加了一个机制:固定1分钟直播延迟,导致并发bug,可以测试一下

jhzgjhzg commented 1 year ago

有什么新进展吗

z0z0r4 commented 1 year ago

估计不会有进展...