From f73f438d32e6a16903dc87744b344d3260725c07 Mon Sep 17 00:00:00 2001 From: Davte Date: Tue, 11 Feb 2020 17:28:37 +0100 Subject: [PATCH] Use built-in decoding feature of `aiohttp.ClientResponse` --- davtelepot/__init__.py | 2 +- davtelepot/utilities.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 14a6ffe..0a4f9be 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.3.24" +__version__ = "2.3.25" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/utilities.py b/davtelepot/utilities.py index 3f84475..f29f4bf 100644 --- a/davtelepot/utilities.py +++ b/davtelepot/utilities.py @@ -161,7 +161,7 @@ async def async_post(url, mode='html', **kwargs): ) -async def async_request(url, type='get', mode='json', encoding='utf-8', +async def async_request(url, type='get', mode='json', encoding=None, **kwargs): """Make an async html request. @@ -184,9 +184,12 @@ async def async_request(url, type='get', mode='json', encoding='utf-8', if type == 'get' else s.post(url, timeout=30, data=kwargs) ) as r: - result = await r.read() if mode in ['html', 'json', 'string']: - result = result.decode(encoding) + result = await r.text(encoding=encoding) + else: + result = await r.read() + if encoding is not None: + result = result.decode(encoding) except Exception as e: logging.error( 'Error making async request to {}:\n{}'.format(