def get_api_result(path, params=None, data=None, skipdns=False):
    import requests
    result = None
    r = None

    headers = get_request_defheaders()
    url = __apiurl__
    if skipdns:
        url = "http://%s" % __apiip__
        headers['host'] = __apiurl__[__apiurl__.index("://")+3:]

    try:
        if data:
            r = requests.post(
                url + path, params=params, data=data, headers=headers)
        else:
            r = requests.get(url + path, params=params, headers=headers)
        r.raise_for_status()
        result = r.json()
    except requests.exceptions.HTTPError as e:
        if result and "errors" in result:
            raise exception.APIRequestError(result['errors'][0]['title'])
        else:
            raise exception.APIRequestError(e)
    except (requests.exceptions.ConnectionError,
            requests.exceptions.ConnectTimeout,
            requests.exceptions.ReadTimeout):
        if not skipdns:
            return get_api_result(path, params, data, skipdns=True)
        raise exception.APIRequestError(
            "Could not connect to PlatformIO Registry Service. "
            "Please try later.")
    except ValueError:
        raise exception.APIRequestError(
            "Invalid response: %s" % r.text.encode("utf-8"))
    finally:
        if r:
            r.close()
    return result
dataset/ETHPy150Open platformio/platformio/platformio/util.py/get_api_result/original