From dbe829e4220064cfe9b35a54f0258d2de3e4eed6 Mon Sep 17 00:00:00 2001 From: MS-Rex <110037899+MS-Rex@users.noreply.github.com> Date: Thu, 26 Sep 2024 04:55:55 +0530 Subject: [PATCH] Cannot connect to host SSLCertVerificationError fixes --- mkbsd.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mkbsd.py b/mkbsd.py index 2b33310..d89bd4c 100644 --- a/mkbsd.py +++ b/mkbsd.py @@ -4,9 +4,12 @@ import os import time import aiohttp import asyncio +import ssl from urllib.parse import urlparse + url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s' + async def delay(ms): await asyncio.sleep(ms / 1000) @@ -23,7 +26,12 @@ async def download_image(session, image_url, file_path): async def main(): try: - async with aiohttp.ClientSession() as session: + # Create an SSL context that does not verify certificates + ssl_context = ssl.create_default_context() + ssl_context.check_hostname = False + ssl_context.verify_mode = ssl.CERT_NONE + + async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=ssl_context)) as session: async with session.get(url) as response: if response.status != 200: raise Exception(f"⛔ Failed to fetch JSON file: {response.status}") @@ -73,4 +81,4 @@ def ascii_art(): if __name__ == "__main__": ascii_art() time.sleep(5) - asyncio.run(main()) + asyncio.run(main()) \ No newline at end of file