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
评论列表
文章目录