forked from platformio/platformio-core
Improve DNS lookup for PlatformIO API
This commit is contained in:
@ -9,7 +9,8 @@ PlatformIO 2.0
|
|||||||
|
|
||||||
* Launched `PlatformIO Community Forums <http://community.platformio.org>`_
|
* Launched `PlatformIO Community Forums <http://community.platformio.org>`_
|
||||||
(`issue #530 <https://github.com/platformio/platformio/issues/530>`_)
|
(`issue #530 <https://github.com/platformio/platformio/issues/530>`_)
|
||||||
* Disable progress bar for download operations when prompts are disabled
|
* Improved DNS lookup for PlatformIO API
|
||||||
|
* Disabled progress bar for download operations when prompts are disabled
|
||||||
* Fixed multiple definition errors for ST STM32 development platform and mbed
|
* Fixed multiple definition errors for ST STM32 development platform and mbed
|
||||||
framework
|
framework
|
||||||
(`issue #571 <https://github.com/platformio/platformio/issues/571>`_)
|
(`issue #571 <https://github.com/platformio/platformio/issues/571>`_)
|
||||||
|
@ -33,6 +33,7 @@ __license__ = "Apache Software License"
|
|||||||
__copyright__ = "Copyright 2014-2016 Ivan Kravets"
|
__copyright__ = "Copyright 2014-2016 Ivan Kravets"
|
||||||
|
|
||||||
__apiurl__ = "http://api.platformio.org"
|
__apiurl__ = "http://api.platformio.org"
|
||||||
|
__apiip__ = "178.62.159.183"
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info >= (3, 0, 0):
|
if sys.version_info >= (3, 0, 0):
|
||||||
|
@ -24,7 +24,7 @@ from os.path import abspath, basename, dirname, expanduser, isdir, isfile, join
|
|||||||
from platform import system, uname
|
from platform import system, uname
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from platformio import __apiurl__, __version__, exception
|
from platformio import __apiip__, __apiurl__, __version__, exception
|
||||||
|
|
||||||
# pylint: disable=wrong-import-order
|
# pylint: disable=wrong-import-order
|
||||||
try:
|
try:
|
||||||
@ -322,18 +322,26 @@ def get_request_defheaders():
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
def get_api_result(path, params=None, data=None):
|
def get_api_result(path, params=None, data=None, skipdns=False):
|
||||||
import requests
|
import requests
|
||||||
result = None
|
result = None
|
||||||
r = None
|
r = None
|
||||||
|
|
||||||
|
headers = get_request_defheaders()
|
||||||
|
url = __apiurl__
|
||||||
|
if skipdns:
|
||||||
|
url = "http://%s" % __apiip__
|
||||||
|
headers['host'] = __apiurl__[__apiurl__.index("://")+3:]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if data:
|
if data:
|
||||||
r = requests.post(__apiurl__ + path, params=params, data=data,
|
r = requests.post(
|
||||||
headers=get_request_defheaders())
|
url + path, params=params, data=data, headers=headers,
|
||||||
|
timeout=(3, 13)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
r = requests.get(__apiurl__ + path, params=params,
|
r = requests.get(
|
||||||
headers=get_request_defheaders())
|
url + path, params=params, headers=headers, timeout=(3, 13))
|
||||||
result = r.json()
|
result = r.json()
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
@ -342,6 +350,8 @@ def get_api_result(path, params=None, data=None):
|
|||||||
else:
|
else:
|
||||||
raise exception.APIRequestError(e)
|
raise exception.APIRequestError(e)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
|
if not skipdns:
|
||||||
|
return get_api_result(path, params, data, skipdns=True)
|
||||||
raise exception.APIRequestError(
|
raise exception.APIRequestError(
|
||||||
"Could not connect to PlatformIO Registry Service. "
|
"Could not connect to PlatformIO Registry Service. "
|
||||||
"Please try later.")
|
"Please try later.")
|
||||||
|
Reference in New Issue
Block a user