def get_infoblox_stream_response_obj()

in Solutions/Infoblox/Data Connectors/InfobloxCloudDataConnector/InfobloxCurrentToAzureStorage/infoblox_to_azure_storage.py [0:0]


    def get_infoblox_stream_response_obj(self, url, query_parameters=None):
        """Return the response object obtained from Infoblox.

        Args:
            url: The URL to send the request to
            query_parameters: Optional query parameters (default is None)

        Returns:
            The response object from the URL request
        """
        __method_name = inspect.currentframe().f_code.co_name
        try:
            max_retries = consts.MAX_RETRIES
            for _ in range(max_retries):
                response = requests.get(url=url, headers=self.headers, params=query_parameters, stream=True)
                if response.status_code == 200:
                    applogger.info(
                        self.log_format.format(
                            consts.LOGS_STARTS_WITH,
                            __method_name,
                            self.azure_function_name,
                            "Got response object, Status Code = {}".format(response.status_code),
                        )
                    )
                    return response
                elif response.status_code == 500:
                    applogger.error(
                        self.log_format.format(
                            consts.LOGS_STARTS_WITH,
                            __method_name,
                            self.azure_function_name,
                            "Internal Server Error, Retrying..., Status Code = {}".format(response.status_code),
                        )
                    )
                    continue
                elif response.status_code == 429:
                    applogger.error(
                        self.log_format.format(
                            consts.LOGS_STARTS_WITH,
                            __method_name,
                            self.azure_function_name,
                            "Rate Limit Exceeded, Retrying..., Status Code = {}".format(response.status_code),
                        )
                    )
                    continue
                elif response.status_code == 401:
                    applogger.error(
                        self.log_format.format(
                            consts.LOGS_STARTS_WITH,
                            __method_name,
                            self.azure_function_name,
                            "Unauthorized, Provide valid API TOKEN, Status Code = {}".format(response.status_code),
                        )
                    )
                    raise InfobloxException()
                elif response.status_code == 403:
                    applogger.error(
                        self.log_format.format(
                            consts.LOGS_STARTS_WITH,
                            __method_name,
                            self.azure_function_name,
                            "Forbidden, user does not have access to this API, Status Code = {}".format(
                                response.status_code
                            ),
                        )
                    )
                    raise InfobloxException()
                else:
                    applogger.error(
                        self.log_format.format(
                            consts.LOGS_STARTS_WITH,
                            __method_name,
                            self.azure_function_name,
                            "Unexpected error, Status Code = {}, Error-{}".format(
                                response.status_code, response.content
                            ),
                        )
                    )
                    raise InfobloxException()
            applogger.error(
                self.log_format.format(
                    consts.LOGS_STARTS_WITH,
                    __method_name,
                    self.azure_function_name,
                    "Max retries reached",
                )
            )
            raise InfobloxException()
        except requests.ConnectionError as conn_err:
            applogger.error(
                self.log_format.format(
                    consts.LOGS_STARTS_WITH,
                    __method_name,
                    self.azure_function_name,
                    "Connection error : Error-{}".format(conn_err),
                )
            )
            raise InfobloxException()
        except requests.HTTPError as http_err:
            applogger.error(
                self.log_format.format(
                    consts.LOGS_STARTS_WITH,
                    __method_name,
                    self.azure_function_name,
                    "HTTP error : Error-{}".format(http_err),
                )
            )
            raise InfobloxException()
        except requests.Timeout as timeout_err:
            applogger.error(
                self.log_format.format(
                    consts.LOGS_STARTS_WITH,
                    __method_name,
                    self.azure_function_name,
                    "Timeout error : Error-{}".format(timeout_err),
                )
            )
            raise InfobloxException()
        except requests.RequestException as request_err:
            applogger.error(
                self.log_format.format(
                    consts.LOGS_STARTS_WITH,
                    __method_name,
                    self.azure_function_name,
                    "Request error : Error-{}".format(request_err),
                )
            )
            raise InfobloxException()
        except Exception as err:
            applogger.error(
                self.log_format.format(
                    consts.LOGS_STARTS_WITH,
                    __method_name,
                    self.azure_function_name,
                    consts.UNEXPECTED_ERROR_MSG.format(err),
                )
            )
            raise InfobloxException()