Ejemplo n.º 1
0
    def raise_for_status(self) -> None:
        """
        Raise the `HttpError` if one occurred.
        """
        message = (
            "{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}\n"
            "For more information check: https://httpstatuses.com/{0.status_code}"
        )

        if StatusCode.is_client_error(self.status_code):
            message = message.format(self, error_type="Client Error")
            raise HTTPError(message, response=self)
        elif StatusCode.is_server_error(self.status_code):
            message = message.format(self, error_type="Server Error")
            raise HTTPError(message, response=self)
Ejemplo n.º 2
0
    def raise_for_status(self) -> None:
        """
        Raise the `HTTPStatusError` if one occurred.
        """
        request = self._request
        if request is None:
            raise RuntimeError("Cannot call `raise_for_status` as the request "
                               "instance has not been set on this response.")

        if self.is_success:
            return

        if self.has_redirect_location:
            message = (
                "{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'\n"
                "Redirect location: '{0.headers[location]}'\n"
                "For more information check: https://httpstatuses.com/{0.status_code}"
            )
        else:
            message = (
                "{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'\n"
                "For more information check: https://httpstatuses.com/{0.status_code}"
            )

        status_class = self.status_code // 100
        error_types = {
            1: "Informational response",
            3: "Redirect response",
            4: "Client error",
            5: "Server error",
        }
        error_type = error_types.get(status_class, "Invalid status code")
        message = message.format(self, error_type=error_type)
        raise HTTPStatusError(message, request=request, response=self)
Ejemplo n.º 3
0
    def raise_for_status(self) -> None:
        """
        Raise the `HttpError` if one occurred.
        """
        message = (
            "{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}\n"
            "For more information check: https://httpstatuses.com/{0.status_code}"
        )

        if 400 <= self.status_code < 500:
            message = message.format(self, error_type="Client Error")
        elif 500 <= self.status_code < 600:
            message = message.format(self, error_type="Server Error")
        else:
            message = ""

        if message:
            raise HttpError(message)
Ejemplo n.º 4
0
    def raise_for_status(self) -> None:
        """
        Raise the `HTTPStatusError` if one occurred.
        """
        message = (
            "{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}\n"
            "For more information check: https://httpstatuses.com/{0.status_code}"
        )

        request = self._request
        if request is None:
            raise RuntimeError("Cannot call `raise_for_status` as the request "
                               "instance has not been set on this response.")

        if codes.is_client_error(self.status_code):
            message = message.format(self, error_type="Client Error")
            raise HTTPStatusError(message, request=request, response=self)
        elif codes.is_server_error(self.status_code):
            message = message.format(self, error_type="Server Error")
            raise HTTPStatusError(message, request=request, response=self)
Ejemplo n.º 5
0
def build(data):
    """Creates email for each key in data object

    Builds msg.html for each key in dictionary.
    """
    for key in data:
        if data[key]['owner'] not in ignore_list:
            msg = email.message.Message()
            msg.add_header('Content-Type', 'text/html')
            msg['Subject'] = 'The Hive Tasking Reminder'
            msg['From'] = 'SIRP-Reminders@' + domain
            msg['To'] = data[key]['owner'] + '@' + domain
            with open('msg.html', 'r') as f:
                message = f.read()
            fmessage = message.format(Name=str(
                data[key]['owner'].split('.')[0]).capitalize(),
                                      Case=str(data[key]['id']))
            print(msg['From'])
            print(msg['To'])
            msg.set_payload(fmessage)
            smtp = smtplib.SMTP(smtp_server)
            smtp.starttls()
            smtp.sendmail(msg['From'], [msg['To']], msg.as_string())
            smtp.quit()
Ejemplo n.º 6
0
 def _log(self, message, *args, **kwargs):# rec=0, verbosity=1):
     """
     Log a message using :mod:`syslog` as well as :attr:`sys.stdout`.
     
     :param   message: The pre-formatted log message.
     :param       rec: Optional recursion level used to indent messages.
     :param verbosity: Minimal verbosity required to display this message.
     :returns: :const:`None`
     """
     
     verbosity = kwargs.get('verbosity', 1)
     rec       = kwargs.get('rec', 0)
     
     if self._conf.verbose and self._conf.verbosity >= verbosity:
         format_args = []
         
         for a in args:
             if isinstance(a, unicode):
                 format_args.append(a.encode('UTF-8'))
             else:
                 format_args.append(a)
         
         if isinstance(message, unicode):
             message = message.encode('UTF-8')
         
         message = '{0}{1}'.format(' '*rec, message.format(*format_args))
         if verbosity < 2:
             if message.strip().startswith('!!!'):
                 self._logger.error(message)
             else:
                 self._logger.info(message)
         else:
             if message.strip().startswith('!!!'):
                 self._logger.warning(message)
             else:
                 self._logger.debug(message)
Ejemplo n.º 7
0
    def _log(self, message, *args, **kwargs):  # rec=0, verbosity=1):
        """
        Log a message using :mod:`syslog` as well as :attr:`sys.stdout`.
        
        :param   message: The pre-formatted log message.
        :param       rec: Optional recursion level used to indent messages.
        :param verbosity: Minimal verbosity required to display this message.
        :returns: :const:`None`
        """

        verbosity = kwargs.get('verbosity', 1)
        rec = kwargs.get('rec', 0)

        if self._conf.verbose and self._conf.verbosity >= verbosity:
            format_args = []

            for a in args:
                if isinstance(a, unicode):
                    format_args.append(a.encode('UTF-8'))
                else:
                    format_args.append(a)

            if isinstance(message, unicode):
                message = message.encode('UTF-8')

            message = '{0}{1}'.format(' ' * rec, message.format(*format_args))
            if verbosity < 2:
                if message.strip().startswith('!!!'):
                    self._logger.error(message)
                else:
                    self._logger.info(message)
            else:
                if message.strip().startswith('!!!'):
                    self._logger.warning(message)
                else:
                    self._logger.debug(message)