添加HTTP请求超时

This commit is contained in:
John Smith 2021-03-28 17:47:23 +08:00
parent 7b50f1ea9c
commit 4669b2c1c9

View File

@ -361,7 +361,7 @@ class BLiveClient:
self._future = None
if session is None:
self._session = aiohttp.ClientSession(loop=self._loop)
self._session = aiohttp.ClientSession(loop=self._loop, timeout=aiohttp.ClientTimeout(total=10))
self._own_session = True
else:
self._session = session
@ -469,7 +469,7 @@ class BLiveClient:
return False
if not self._parse_room_init(data['data']):
return False
except aiohttp.ClientConnectionError:
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
logger.exception('room %d init_room失败', self._tmp_room_id)
return False
return True
@ -495,7 +495,7 @@ class BLiveClient:
return False
if not self._parse_danmaku_server_conf(data['data']):
return False
except aiohttp.ClientConnectionError:
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
logger.exception('room %d getConf失败', self._room_id)
return False
return True