我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用flask.request.scheme()。
def after_request(response): timestamp = strftime('[%Y-%b-%d %H:%M]') f = open("server.log","a").write( "\n"+"--"*10+"\n"+'%s %s %s %s %s %s'%(timestamp, request.remote_addr, request.method, request.scheme, request.full_path, response.status) ) return response
def exceptions(e): tb = traceback.format_exc() timestamp = strftime('[%Y-%b-%d %H:%M]') f = open("server.log","a").write( "\n"+"--"*10+"\n"+'%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s'%(timestamp, request.remote_addr, request.method, request.scheme, request.full_path, tb) ) return abort(500)
def internal_server_error(e): message = repr(e) trace = traceback.format_exc() trace = string.split(trace, '\n') timestamp = (datetime.fromtimestamp(time.time()) .strftime('%Y-%m-%d %H:%M:%S')) if current_user.is_authenticated: user = current_user.username else: user = 'anonymous' gathered_data = ('message: {}\n\n\n' 'timestamp: {}\n' 'ip: {}\n' 'method: {}\n' 'request.scheme: {}\n' 'request.full_path: {}\n' 'user: {}\n\n\n' 'trace: {}'.format(message, timestamp, request.remote_addr, request.method, request.scheme, request.full_path, user, '\n'.join(trace))) # send email to admin if app.config['TESTING']: print(gathered_data) else: mail_message = gathered_data msg = Message('Error: ' + message[:40], body=mail_message, recipients=[app.config['ADMIN_MAIL']]) mail.send(msg) flash(_('A message has been sent to the administrator'), 'info') bookcloud_before_request() return render_template('500.html', message=gathered_data), 500
def after_request(response): logger.info('%s %s %s %s %s', request.remote_addr, request.method, request.scheme, request.full_path, response.status) return response
def exceptions(e): tb = traceback.format_exc() logger.error('%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s', request.remote_addr, request.method, request.scheme, request.full_path, tb) return e.status_code
def after_request(response): logger.info('%s %s %s %s %s', request.method, request.environ.get('HTTP_X_REAL_IP', request.remote_addr), request.scheme, request.full_path, response.status) return response
def exceptions(e): tb = traceback.format_exc() tb = tb.decode('utf-8') logger.error('%s %s %s %s 5xx INTERNAL SERVER ERROR\n%s', request.environ.get('HTTP_X_REAL_IP', request.remote_addr), request.method, request.scheme, request.full_path, tb) return '500 INTERNAL SERVER ERROR', 500
def after_request(response): timestamp = strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s %s',timestamp , request.remote_addr , \ request.method , request.scheme , request.full_path , response.status) return response
def exceptions(e): tb = traceback.format_exc() timestamp = strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, tb) return make_response(e , 405)
def auth0_login(): """ Login through external auth provider --- tags: - auth """ callback_url = request.scheme + '://' + request.headers['Host'] + '/api/auth/callback' return app.config['github'].authorize(callback=callback_url)
def after_request(response): timestamp = strftime('%Y-%b-%d %H:%M:%S') useragent = request.user_agent logger.info('[%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]', timestamp, request.remote_addr, useragent, request.method, request.scheme, request.full_path, response.status, request.referrer) return response
def exceptions(e): tb = traceback.format_exc() timestamp = strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, tb) return e.status_code #Run the main app...