def https_response(self, req, res):
        """Handle https_response.

        If the response is from the cosign login page (starts with
        self.login_url) then log in to cosign and retry. Otherwise
        continue as normal.
        """
        if res.code == 200 and res.geturl().startswith(self.login_url + '?'):
            # Been redirected to login page.

            # We'll need the cosign cookies later
            self.cj.extract_cookies(res, req)

            # Grab a username and password.
            data = urllib.parse.urlencode(self.pw_mgr.get_cred())

            # Construct a login POST request to the login page.
            req2 = urllib.request.Request(
                self.login_url,
                data.encode('iso-8859-1'),
                )
            # We need a different opener that doesn't have a CosignHandler.
            opener = urllib.request.build_opener(
                urllib.request.HTTPCookieProcessor(self.cj)
                )
            # Try the login
            res2 = opener.open(req2)
            # Cookies, cookies, cookies
            self.cj.extract_cookies(res2, req2)

            # We should be logged in, go back and get what was asked for
            res = opener.open(req)

            # If we end up back at the login page then login failed
            if res.geturl().startswith(self.login_url + '?'):
                raise Exception('Login failed.')

            if self.save_cookies:
                self.cj.extract_cookies(res,req)
                self.cj.save(ignore_discard=True)

        return res
Handle https_response.

        If the response is from the cosign login page (starts with
        self.login_url) then log in to cosign and retry. Otherwise
        continue as normal.
        
recipes/Python/578217_Cosign_Handler/recipe-578217.py