mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-03-23 00:00:38 +08:00
临时修复获取头像请求被屏蔽的问题
This commit is contained in:
parent
6c84cbb930
commit
062e7ed1aa
@ -308,8 +308,9 @@ class RoomInfoHandler(api.base.ApiHandler): # noqa
|
|||||||
async with utils.request.http_session.get(
|
async with utils.request.http_session.get(
|
||||||
blivedm_client.ROOM_INIT_URL,
|
blivedm_client.ROOM_INIT_URL,
|
||||||
headers={
|
headers={
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
|
**utils.request.BILIBILI_COMMON_HEADERS,
|
||||||
' Chrome/102.0.0.0 Safari/537.36'
|
'Origin': 'https://live.bilibili.com',
|
||||||
|
'Referer': f'https://live.bilibili.com/{room_id}'
|
||||||
},
|
},
|
||||||
params={
|
params={
|
||||||
'room_id': room_id
|
'room_id': room_id
|
||||||
|
@ -150,11 +150,15 @@ async def _do_get_avatar_url_from_web(user_id):
|
|||||||
async with utils.request.http_session.get(
|
async with utils.request.http_session.get(
|
||||||
'https://api.bilibili.com/x/space/acc/info',
|
'https://api.bilibili.com/x/space/acc/info',
|
||||||
headers={
|
headers={
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
|
**utils.request.BILIBILI_COMMON_HEADERS,
|
||||||
' Chrome/102.0.0.0 Safari/537.36'
|
'Origin': 'https://space.bilibili.com',
|
||||||
|
'Referer': f'https://space.bilibili.com/{user_id}/'
|
||||||
},
|
},
|
||||||
params={
|
params={
|
||||||
'mid': user_id
|
'mid': user_id,
|
||||||
|
'token': '',
|
||||||
|
'platform': 'web',
|
||||||
|
'jsonp': 'jsonp'
|
||||||
}
|
}
|
||||||
) as r:
|
) as r:
|
||||||
if r.status != 200:
|
if r.status != 200:
|
||||||
@ -168,6 +172,11 @@ async def _do_get_avatar_url_from_web(user_id):
|
|||||||
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if data['code'] != 0:
|
||||||
|
# 这里虽然失败但不会被ban一段时间
|
||||||
|
logger.info('Failed to fetch avatar: code=%d %s uid=%d', data['code'], data['message'], user_id)
|
||||||
|
return None
|
||||||
|
|
||||||
avatar_url = process_avatar_url(data['data']['face'])
|
avatar_url = process_avatar_url(data['data']['face'])
|
||||||
update_avatar_cache(user_id, avatar_url)
|
update_avatar_cache(user_id, avatar_url)
|
||||||
return avatar_url
|
return avatar_url
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
# 不带这堆头部有时候也能成功请求,但是带上后成功的概率更高
|
||||||
|
BILIBILI_COMMON_HEADERS = {
|
||||||
|
'Origin': 'https://www.bilibili.com',
|
||||||
|
'Referer': 'https://www.bilibili.com/',
|
||||||
|
'Sec-CH-UA': '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
|
||||||
|
'Sec-CH-UA-Mobile': '?0',
|
||||||
|
'Sec-CH-UA-Platform': '"Windows"',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Site': 'same-site',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
|
||||||
|
' Chrome/105.0.0.0 Safari/537.36'
|
||||||
|
}
|
||||||
|
|
||||||
http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10))
|
http_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10))
|
||||||
|
Loading…
Reference in New Issue
Block a user