From 07a1763ef45860570e187cda7ec8e638f8e2f66c Mon Sep 17 00:00:00 2001 From: Allen Wittenauer Date: Fri, 12 May 2023 22:09:12 -0700 Subject: [PATCH] twitch user image download should be async (#813) --- nowplaying/twitch/__init__.py | 2 -- nowplaying/twitch/utils.py | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nowplaying/twitch/__init__.py b/nowplaying/twitch/__init__.py index 2b13fcb8..5cfbfbe5 100644 --- a/nowplaying/twitch/__init__.py +++ b/nowplaying/twitch/__init__.py @@ -9,8 +9,6 @@ import time import traceback -import requests - from twitchAPI.twitch import Twitch from twitchAPI.helper import first from twitchAPI.types import AuthScope diff --git a/nowplaying/twitch/utils.py b/nowplaying/twitch/utils.py index 882ca5fc..670153ba 100644 --- a/nowplaying/twitch/utils.py +++ b/nowplaying/twitch/utils.py @@ -27,8 +27,9 @@ async def get_user_image(twitch, loginname): image = None try: user = await first(twitch.get_users(logins=loginname)) - req = requests.get(user.profile_image_url, timeout=5) - image = nowplaying.utils.image2png(req.content) + async with aiohttp.ClientSession() as session: + async with session.get(user.profile_image_url, timeout=5) as resp: + image = nowplaying.utils.image2png(await resp.read()) except Exception as error: #pylint: disable=broad-except logging.error(error) return image