diff --git a/pagermaid/modules/plugin.py b/pagermaid/modules/plugin.py index ed65e84..4332e53 100644 --- a/pagermaid/modules/plugin.py +++ b/pagermaid/modules/plugin.py @@ -32,8 +32,8 @@ def remove_plugin(name): async def download(name): html = await get(f'{git_source}{name}.py') - with open(f'plugins/{name}.py', mode='wb') as f: - f.write(html.content) + with open(f'plugins/{name}.py', mode='w') as f: + f.write(html.text) return f'plugins/{name}.py' diff --git a/pagermaid/modules/status.py b/pagermaid/modules/status.py index 1bf15d2..b7e5169 100644 --- a/pagermaid/modules/status.py +++ b/pagermaid/modules/status.py @@ -196,7 +196,7 @@ async def speedtest(context): f"Timestamp: `{result['timestamp']}`" ) # 开始处理图片 - data = (await get(f"{result['result']['url']}.png")).content + data = (await get(f"{result['result']['url']}.png")).text with open('speedtest.png', mode='wb') as f: f.write(data) try: @@ -273,7 +273,7 @@ async def speedtest(context): f"Timestamp: `{result['timestamp']}`" ) # 开始处理图片 - data = (await get(result['share'])).content + data = (await get(result['share'])).text with open('speedtest.png', mode='wb') as f: f.write(data) try: diff --git a/pagermaid/utils.py b/pagermaid/utils.py index c2de03f..08a2f6e 100644 --- a/pagermaid/utils.py +++ b/pagermaid/utils.py @@ -25,10 +25,10 @@ class AiohttpResp: """ 重写返回类型。 """ - def __init__(self, text: str, content: bytes, status_code: int): + def __init__(self, text: Any, content: bytes, status_code: int): """ Args: - text (str): 网页内容 + text (Any): 网页内容 content (bytes): 文件内容 status_code (int): 网页状态码 """ @@ -286,7 +286,10 @@ async def request(method: str, session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=timeout)) resp = await session.request(**config_) # 返回请求 - resp_data = await resp.text() + try: + resp_data = await resp.text() + except UnicodeDecodeError: + resp_data = await resp.read() content = await resp.content.read() status_code = resp.status await session.close()