def api_up(url, json=None, verb='get', uauth=None): headers = {'X-Forwarded-For': request.remote_addr} auth_tup = uauth if uauth else (session['user'].username, session['user'].wurd) retdata = dict() try: response = getattr(requests, verb)(api_base_url + url, json=json, auth=auth_tup, headers=headers) retdata = response.json() except Exception as e: logger.error('+! Unable to contact API !+') flash('Critical error contacting ESPA-API', 'error') if isinstance(retdata, dict): if 'message' in retdata and retdata.get( 'message') == 'Internal Server Error': flash( 'Critical error contacting ESPA-API, admins have been notified.', 'error') messages = retdata.pop('messages', dict()) if 'errors' in messages: flash(format_messages(messages.get('errors')), 'error') if 'warnings' in messages: flash(format_messages(messages.get('warnings')), 'warning') return retdata
def page_not_found(e): message = { '404: Not Found': [ 'The requested URL was not found on the ' 'server.', 'If you entered the URL manually ' 'please check your spelling and try again.' ] } flash(format_messages(message), category='warning') return render_template('base.html')
def internal_error(e): logger.error('Internal Server Error: {}\n\n'.format( traceback.format_exc())) message = { '500 Internal Server Error': [ 'Sorry, something went wrong.', 'A programming error has caused ' 'the page to fail rendering.', 'Contact the Site Admin ASAP' ] } flash(format_messages(message), category='error') return render_template('base.html')
remove['Unknown IDs'] = not_implemented date_restricted = scene_dict_all_prods.pop('date_restricted', None) if date_restricted: products = map(str, set(date_restricted.keys()) & set(data.keys())) unique_ids = map( str, set([u for v in date_restricted.values() for u in v])) if len(products): remove['Missing Auxiliary Data for %s' % products] = unique_ids errors = [ '{}. Invalid IDs must be removed: {}'.format(key, values) for key, values in remove.items() ] if errors: flash(format_messages(errors), category='error') return redirect(url_for('new_order')) # create a list of requested products, but make sure not to include Modis, Viirs, or Sentinel # with requested additional processing for landsat landsat_list = list() for key in data: if key in conversions['products']: if 'modis_' not in key and 'viirs_' not in key and 's2_' not in key: landsat_list.append(key) # now that we have the product list, lets remove # this key from the form inputs for p in landsat_list: data.pop(p)