def get_token(url): try: response = urlopen(url + '?auth_manager_token=' + API_TUTOR_TOKEN) data = response.read() results = data.decode('utf-8', 'ignore') return json.loads(results)['token'] except urllib.error.HTTPError as e: # give a good error message: error = utilities.get_error_message(e, url) raise Exception(error)
def _send_get_request(url: str): token = authentication.get_token('https://www.apitutor.org/yelp/key') request = urllib.request.Request(url, None, {'Authorization': 'Bearer ' + token}) try: with urllib.request.urlopen(request) as response: data = json.loads(response.read().decode()) return data except urllib.error.HTTPError as e: # give a good error message: error = utilities.get_error_message(e, url) raise Exception(error)