HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/flower/api/__init__.py
import os

import tornado.web

from ..utils import strtobool
from ..views import BaseHandler


class BaseApiHandler(BaseHandler):
    def prepare(self):
        enable_api = strtobool(os.environ.get(
            'FLOWER_UNAUTHENTICATED_API') or "false")
        if not (self.application.options.basic_auth or self.application.options.auth) and not enable_api:
            raise tornado.web.HTTPError(
                401, "FLOWER_UNAUTHENTICATED_API environment variable is required to enable API without authentication")

    def write_error(self, status_code, **kwargs):
        exc_info = kwargs.get('exc_info')
        log_message = exc_info[1].log_message
        if log_message:
            self.write(log_message)
        self.set_status(status_code)
        self.finish()