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)
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)
def basic_auth(url): headers = { 'Accept': 'application/json', } return http.request(url, headers, auth=(app.config['STUDENT_API_USER'], app.config['STUDENT_API_PWD']))
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)
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)
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)
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)
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
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)
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'])
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)
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']))
def authorized_request(url): auth_headers = { 'Authorization': 'Bearer {}'.format(app.config['CANVAS_HTTP_TOKEN']) } return http.request(url, auth_headers)
def authorized_request(url): auth_headers = {'Authorization': 'Bearer {}'.format(_get_token())} return http.request(url, auth_headers)