From 1d25419ae173dcb928c45ef060c26a9f29599221 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 31 Jul 2023 18:01:01 +0300 Subject: [PATCH] Use "platformio.public.fetch_http_content" API for HTTP requests --- platform.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/platform.py b/platform.py index 516fed4..50ce912 100644 --- a/platform.py +++ b/platform.py @@ -17,7 +17,6 @@ import urllib import sys import json import re -import requests from platformio.public import PlatformBase, to_unix_path @@ -349,16 +348,15 @@ class Espressif32Platform(PlatformBase): ) index_file_url = _prepare_url_for_index_file(url_items) - r = requests.get(index_file_url, timeout=10) - if r.status_code != 200: - raise ValueError( - ( - "Failed to download package index file due to a bad response (%d) " - "from the remote `%s`" - ) - % (r.status_code, index_file_url) - ) - return r.json() + + try: + from platformio.public import fetch_http_content + content = fetch_http_content(index_file_url) + except ImportError: + import requests + content = requests.get(index_file_url, timeout=5).text + + return json.loads(content) def configure_arduino_toolchains(self, package_index): if not package_index: