def _initiate_request()

in src/mapillary/models/client.py [0:0]


    def _initiate_request(self, url: str, method: str, params: dict = None):
        """
        Private method - For internal use only.
        This method is responsible for making tailored API requests to the mapillary API v4.
        It generalizes the requests and ties them to the same session.

        :param url: The request endpoint - required
        :type url: str

        :param method: HTTP method to be used - required
        :type method: str

        :param params: Query parameters to be attached to the request - optional
        :type params: dict
        """

        request = requests.Request(method, url, params=params)

        # create a prepared request with the request and the session info merged
        prepped_req = self.session.prepare_request(request)

        # Log the prepped request before sending it.
        Client._pprint_request(prepped_req)

        # Sending the request
        res = self.session.send(prepped_req)

        # Log the responses
        Client._pprint_response(res)

        # Handling the response status codes
        if res.status_code == requests.codes.ok:

            try:
                logger.debug(f"Response: {res.json()}")

            except ValueError:
                return res

        elif res.status_code >= 400:

            logger.error(f"Server responded with a {str(res.status_code)} error!")

            try:
                logger.debug(f"Error details: {str(res.json())}")

            except ValueError:
                logger.debug(
                    "[Client - _initiate_request, ValueError] res.json() not available,"
                    "empty response"
                )

            res.raise_for_status()

        return res