fix(platform-bilibili/bilibililive):为相关接口添加UA, 修复接口信息获取失败的问题

This commit is contained in:
Azide 2022-09-23 23:17:58 +08:00
parent 8e315d53d3
commit ac505f51d3

View File

@ -27,11 +27,16 @@ class Bilibili(NewMessage):
name = "B站"
has_target = True
parse_target_promot = "请输入用户主页的链接"
UA = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
}
async def get_target_name(self, target: Target) -> Optional[str]:
async with http_client() as client:
res = await client.get(
"https://api.bilibili.com/x/space/acc/info", params={"mid": target}
"https://api.bilibili.com/x/space/acc/info",
params={"mid": target},
headers=self.UA,
)
res_data = json.loads(res.text)
if res_data["code"]:
@ -171,11 +176,16 @@ class Bilibililive(StatusChange):
schedule_kw = {"seconds": 10}
name = "Bilibili直播"
has_target = True
UA = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
}
async def get_target_name(self, target: Target) -> Optional[str]:
async with http_client() as client:
res = await client.get(
"https://api.bilibili.com/x/space/acc/info", params={"mid": target}
"https://api.bilibili.com/x/space/acc/info",
params={"mid": target},
headers=self.UA,
)
res_data = json.loads(res.text)
if res_data["code"]:
@ -188,6 +198,7 @@ class Bilibililive(StatusChange):
res = await client.get(
"https://api.bilibili.com/x/space/acc/info",
params=params,
headers=self.UA,
timeout=4.0,
)
res_dict = json.loads(res.text)