Example #1
0
def make_request(*args, **kwargs):
    response = requests.request(*args, **kwargs)
    if 400 <= response.status_code < 500:
        print('Request failed: {}'.format(response.content))
        raise ImproperCredentialsException('GEM')
    response.raise_for_status()
    return response
Example #2
0
def make_request(*args, **kwargs):
    response = requests.request(*args, **kwargs)
    if 400 <= response.status_code < 500:
        logger.log(msg=f'Gemini request failed: {response.content}',
                   level=logging.WARN)
        raise ImproperCredentialsException('GEM')
    response.raise_for_status()
    return response
Example #3
0
def make_request(*args, **kwargs):
    response = requests.request(*args, **kwargs)
    if 401 <= response.status_code < 500:
        raise ImproperCredentialsException('LCO: ' + str(response.content))
    elif 400 == response.status_code:
        raise forms.ValidationError(f'LCO: {str(response.content)}')
    response.raise_for_status()
    return response
Example #4
0
def get(term):
    get_url = TNS_URL + '/api/get/object'

    # change term to json format
    json_list = [("objname", term)]
    json_file = OrderedDict(json_list)

    # construct the list of (key,value) pairs
    get_data = [('api_key', (None, TNS_CREDENTIALS['api_key'])),
                ('data', (None, json.dumps(json_file)))]

    response = requests.post(get_url, files=get_data)
    response_data = json.loads(response.text)

    if 400 <= response_data.get('id_code') <= 403:
        raise ImproperCredentialsException('TNS: ' + str(response_data.get('id_message')))

    return response_data['data']['reply']
Example #5
0
def make_request(*args, **kwargs):
    response = requests.request(*args, **kwargs)
    if 400 <= response.status_code < 500:
        raise ImproperCredentialsException('LCO: ' + str(response.content))
    response.raise_for_status()
    return response