示例#1
0
def authorized_request(url):
    auth_headers = {
        'app_id': app.config['STUDENT_API_ID'],
        'app_key': app.config['STUDENT_API_KEY'],
        'Accept': 'application/json',
    }
    return http.request(url, auth_headers)
示例#2
0
def authorized_request(url):
    auth_headers = {
        'app_id': app.config['ENROLLMENTS_API_ID'],
        'app_key': app.config['ENROLLMENTS_API_KEY'],
        'Accept': 'application/json',
    }
    return http.request(url, auth_headers, log_404s=False)
示例#3
0
def basic_auth(url):
    headers = {
        'Accept': 'application/json',
    }
    return http.request(url,
                        headers,
                        auth=(app.config['STUDENT_API_USER'],
                              app.config['STUDENT_API_PWD']))
示例#4
0
def request(url, data=None):
    credentials = app.config['API_USERNAME'] + ':' + app.config['API_PASSWORD']
    authorization = 'Basic ' + base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
    headers = {
        'Authorization': authorization,
        'Content-Type': 'application/json',
    }
    return http.request(url, headers=headers, method='post', data=data)
示例#5
0
def request(url):
    timestamp = datetime.utcnow().isoformat()[:-3] + 'Z'
    signature = generate_hmac_signature(url, timestamp)
    authorization = 'HMACAuth ' + app.config['CANVAS_DATA_API_KEY'] + ':' + signature
    headers = {
        'Authorization': authorization,
        'Date': timestamp,
    }
    return http.request(url, headers=headers)
示例#6
0
def _get_asc_feed_response(mock=None):
    url = app.config['ASC_ATHLETES_API_URL']
    with mock(url):
        headers = {
            'Accept': 'application/json',
        }
        auth_params = {
            'ETSkey': app.config['ASC_ATHLETES_API_KEY'],
        }
        return http.request(url, headers, auth_params=auth_params)
示例#7
0
def xkcd():
    try:
        url = http.build_url(
            f'https://xkcd.com/{randint(1, 2427)}/info.0.json')
        json = http.request(url).json()
    except Exception:
        json = {
            'alt': '40% of OpenBSD installs lead to shark attacks.',
            'img': 'https://imgs.xkcd.com/comics/success.png',
        }
    return tolerant_jsonify(json)
示例#8
0
def authorized_request_v2(url):
    if app.config['STUDENT_API_USER']:
        return basic_auth(url)
    auth_headers = {
        'app_id': app.config['STUDENT_API_ID'],
        'app_key': app.config['STUDENT_API_KEY'],
        'Accept': 'application/json',
    }
    response = http.request(url, auth_headers)
    # We are occasionally receiving bad JSON payloads from the API and would like to know why.
    try:
        response and hasattr(response, 'json') and response.json()
    except ValueError as e:
        if hasattr(response, 'content'):
            desc = response.content
        else:
            desc = response
        app.logger.error(
            f'Error on API call {url}, response={desc}, error={e}')
        return
    return response
示例#9
0
def authorized_request(url, api_key):
    # The more typical underscored "app_key" header will be stripped out by the AWS load balancer.
    # A hyphened "app-key" header passes through.
    auth_headers = {'app-key': api_key}
    return http.request(url, auth_headers)
示例#10
0
def _get_cal1card_photo(uid, mock=None):
    url = http.build_url(app.config['CAL1CARD_PHOTO_API_URL'], {'uid': uid})
    with mock(url):
        return http.request(url,
                            auth=cal1card_api_auth(),
                            timeout=app.config['CAL1CARD_PHOTO_API_TIMEOUT'])
示例#11
0
def _get_degree_progress(cs_id, mock=None):
    url = http.build_url(app.config['DEGREE_PROGRESS_API_URL'],
                         {'EMPLID': cs_id})
    with mock(url):
        return http.request(url, auth=cs_api_auth(), log_404s=False)
示例#12
0
def get_authorized_response(url, mock=None):
    with mock(url):
        return http.request(
            url,
            auth=HTTPBasicAuth(app.config['YCBM_API_USERNAME'],
                               app.config['YCBM_API_PASSWORD']))
示例#13
0
def authorized_request(url):
    auth_headers = {
        'Authorization': 'Bearer {}'.format(app.config['CANVAS_HTTP_TOKEN'])
    }
    return http.request(url, auth_headers)
示例#14
0
def authorized_request(url):
    auth_headers = {'Authorization': 'Bearer {}'.format(_get_token())}
    return http.request(url, auth_headers)