Skip to content

Commit

Permalink
Use "platformio.public.fetch_http_content" API for HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Jul 31, 2023
1 parent f1fce6c commit 1d25419
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import sys
import json
import re
import requests

from platformio.public import PlatformBase, to_unix_path

Expand Down Expand Up @@ -349,16 +348,15 @@ def _prepare_url_for_index_file(url_items):
)

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:
Expand Down

0 comments on commit 1d25419

Please sign in to comment.