Skip to content

Commit 1d25419

Browse files
committed
Use "platformio.public.fetch_http_content" API for HTTP requests
1 parent f1fce6c commit 1d25419

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

platform.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import sys
1818
import json
1919
import re
20-
import requests
2120

2221
from platformio.public import PlatformBase, to_unix_path
2322

@@ -349,16 +348,15 @@ def _prepare_url_for_index_file(url_items):
349348
)
350349

351350
index_file_url = _prepare_url_for_index_file(url_items)
352-
r = requests.get(index_file_url, timeout=10)
353-
if r.status_code != 200:
354-
raise ValueError(
355-
(
356-
"Failed to download package index file due to a bad response (%d) "
357-
"from the remote `%s`"
358-
)
359-
% (r.status_code, index_file_url)
360-
)
361-
return r.json()
351+
352+
try:
353+
from platformio.public import fetch_http_content
354+
content = fetch_http_content(index_file_url)
355+
except ImportError:
356+
import requests
357+
content = requests.get(index_file_url, timeout=5).text
358+
359+
return json.loads(content)
362360

363361
def configure_arduino_toolchains(self, package_index):
364362
if not package_index:

0 commit comments

Comments
 (0)