insights/client/connection.py
def handle_fail_rcs(self, req):
        """
        Bail out if we get a 401 and leave a message
        """

        try:
            logger.debug("HTTP Status Code: %s", req.status_code)
            logger.debug("HTTP Response Text: %s", req.text)
            logger.debug("HTTP Response Reason: %s", req.reason)
            logger.debug("HTTP Response Content: %s", req.content)
        except:
            logger.error("Malformed HTTP Request.")

        # attempt to read the HTTP response JSON message
        try:
            logger.debug("HTTP Response Message: %s", req.json()["message"])
        except:
            logger.debug("No HTTP Response message present.")

        # handle specific status codes
        if req.status_code >= 400:
            logger.info("Debug Information:\nHTTP Status Code: %s",
                        req.status_code)
            logger.info("HTTP Status Text: %s", req.reason)
            if req.status_code == 401:
                logger.error("Authorization Required.")
                logger.error("Please ensure correct credentials "
                             "in " + constants.default_conf_file)
                logger.debug("HTTP Response Text: %s", req.text)
            if req.status_code == 402:
                # failed registration because of entitlement limit hit
                logger.debug('Registration failed by 402 error.')
                try:
                    logger.error(req.json()["message"])
                except LookupError:
                    logger.error("Got 402 but no message")
                    logger.debug("HTTP Response Text: %s", req.text)
                except:
                    logger.error("Got 402 but no message")
                    logger.debug("HTTP Response Text: %s", req.text)
            if req.status_code == 403 and self.auto_config:
                # Insights disabled in satellite
                rhsm_hostname = urlparse(self.base_url).hostname
                if (rhsm_hostname != 'subscription.rhn.redhat.com' and
                   rhsm_hostname != 'subscription.rhsm.redhat.com'):
                    logger.error('Please enable Insights on Satellite server '
                                 '%s to continue.', rhsm_hostname)
            if req.status_code == 412:
                try:
                    unreg_date = req.json()["unregistered_at"]
                    logger.error(req.json()["message"])
                    write_unregistered_file(unreg_date)
                except LookupError:
                    unreg_date = "412, but no unreg_date or message"
                    logger.debug("HTTP Response Text: %s", req.text)
                except:
                    unreg_date = "412, but no unreg_date or message"
                    logger.debug("HTTP Response Text: %s", req.text)
            return True
        return False

        Bail out if we get a 401 and leave a message
        
Bail out if we get a 401 and leave a message
Bail out if we get a 401 and leave a message
def handle_fail_rcs(self, req):
        try:
            logger.debug("HTTP Status Code: %s", req.status_code)
            logger.debug("HTTP Response Text: %s", req.text)
            logger.debug("HTTP Response Reason: %s", req.reason)
            logger.debug("HTTP Response Content: %s", req.content)
        except:
            logger.error("Malformed HTTP Request.")
        try:
            logger.debug("HTTP Response Message: %s", req.json()["message"])
        except:
            logger.debug("No HTTP Response message present.")
        if req.status_code >= 400:
            logger.info("Debug Information:\nHTTP Status Code: %s",
                        req.status_code)
            logger.info("HTTP Status Text: %s", req.reason)
            if req.status_code == 401:
                logger.error("Authorization Required.")
                logger.error("Please ensure correct credentials "
                             "in " + constants.default_conf_file)
                logger.debug("HTTP Response Text: %s", req.text)
            if req.status_code == 402:
                logger.debug('Registration failed by 402 error.')
                try:
                    logger.error(req.json()["message"])
                except LookupError:
                    logger.error("Got 402 but no message")
                    logger.debug("HTTP Response Text: %s", req.text)
                except:
                    logger.error("Got 402 but no message")
                    logger.debug("HTTP Response Text: %s", req.text)
            if req.status_code == 403 and self.auto_config:
                rhsm_hostname = urlparse(self.base_url).hostname
                if (rhsm_hostname != 'subscription.rhn.redhat.com' and
                   rhsm_hostname != 'subscription.rhsm.redhat.com'):
                    logger.error('Please enable Insights on Satellite server '
                                 '%s to continue.', rhsm_hostname)
            if req.status_code == 412:
                try:
                    unreg_date = req.json()["unregistered_at"]
                    logger.error(req.json()["message"])
                    write_unregistered_file(unreg_date)
                except LookupError:
                    unreg_date = "412, but no unreg_date or message"
                    logger.debug("HTTP Response Text: %s", req.text)
                except:
                    unreg_date = "412, but no unreg_date or message"
                    logger.debug("HTTP Response Text: %s", req.text)
            return True
        return False
def handle_fail_rcs ( self , req ) : try : logger . debug ( "HTTP Status Code: %s" , req . status_code ) logger . debug ( "HTTP Response Text: %s" , req . text ) logger . debug ( "HTTP Response Reason: %s" , req . reason ) logger . debug ( "HTTP Response Content: %s" , req . content ) except : logger . error ( "Malformed HTTP Request." ) try : logger . debug ( "HTTP Response Message: %s" , req . json ( ) [ "message" ] ) except : logger . debug ( "No HTTP Response message present." ) if req . status_code >= 400 : logger . info ( "Debug Information:\nHTTP Status Code: %s" , req . status_code ) logger . info ( "HTTP Status Text: %s" , req . reason ) if req . status_code == 401 : logger . error ( "Authorization Required." ) logger . error ( "Please ensure correct credentials " "in " + constants . default_conf_file ) logger . debug ( "HTTP Response Text: %s" , req . text ) if req . status_code == 402 : logger . debug ( 'Registration failed by 402 error.' ) try : logger . error ( req . json ( ) [ "message" ] ) except LookupError : logger . error ( "Got 402 but no message" ) logger . debug ( "HTTP Response Text: %s" , req . text ) except : logger . error ( "Got 402 but no message" ) logger . debug ( "HTTP Response Text: %s" , req . text ) if req . status_code == 403 and self . auto_config : rhsm_hostname = urlparse ( self . base_url ) . hostname if ( rhsm_hostname != 'subscription.rhn.redhat.com' and rhsm_hostname != 'subscription.rhsm.redhat.com' ) : logger . error ( 'Please enable Insights on Satellite server ' '%s to continue.' , rhsm_hostname ) if req . status_code == 412 : try : unreg_date = req . json ( ) [ "unregistered_at" ] logger . error ( req . json ( ) [ "message" ] ) write_unregistered_file ( unreg_date ) except LookupError : unreg_date = "412, but no unreg_date or message" logger . debug ( "HTTP Response Text: %s" , req . text ) except : unreg_date = "412, but no unreg_date or message" logger . debug ( "HTTP Response Text: %s" , req . text ) return True return False
Bail out if we get a 401 and leave a message
Bail out if we get a 401 and leave a message
"""
        Bail out if we get a 401 and leave a message
        """ # attempt to read the HTTP response JSON message # handle specific status codes # failed registration because of entitlement limit hit # Insights disabled in satellite
self
req