修复获取头像请求被屏蔽的问题

也修改了其他请求的User-Agent,防止将来被屏蔽
This commit is contained in:
John Smith 2022-06-18 21:31:25 +08:00
parent 1075b458aa
commit 2c0dd6e1c9
4 changed files with 21 additions and 3 deletions

View File

@ -306,7 +306,14 @@ class RoomInfoHandler(api.base.ApiHandler): # noqa
async def _get_room_info(room_id):
try:
async with utils.request.http_session.get(
blivedm_client.ROOM_INIT_URL, params={'room_id': room_id}
blivedm_client.ROOM_INIT_URL,
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/102.0.0.0 Safari/537.36'
},
params={
'room_id': room_id
}
) as res:
if res.status != 200:
logger.warning('room=%d _get_room_info failed: %d %s', room_id,

@ -1 +1 @@
Subproject commit d8f7f6b7828069cb6c1fd13f756cfd891f0b1a46
Subproject commit 2cca7354b1e4e1376d66a4d442480d56e7d5e22f

View File

@ -148,7 +148,14 @@ async def _get_avatar_url_from_web_coroutine(user_id, future):
async def _do_get_avatar_url_from_web(user_id):
try:
async with utils.request.http_session.get(
'https://api.bilibili.com/x/space/acc/info', params={'mid': user_id}
'https://api.bilibili.com/x/space/acc/info',
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/102.0.0.0 Safari/537.36'
},
params={
'mid': user_id
}
) as r:
if r.status != 200:
logger.warning('Failed to fetch avatar: status=%d %s uid=%d', r.status, r.reason, user_id)

View File

@ -424,6 +424,10 @@ class BilibiliTranslateFree(FlowControlTranslateProvider):
try:
async with utils.request.http_session.get(
'https://api.live.bilibili.com/av/v1/SuperChat/messageTranslate',
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/102.0.0.0 Safari/537.36'
},
params={
'room_id': '21396545',
'ruid': '407106379',