<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _get_cookie(self, mgmt_ip, config, refresh=False):
 """Performs authentication and retries cookie."""


        if mgmt_ip not in self.credentials:
            return None

        security_data = self.credentials[mgmt_ip]
        verify = security_data[const.HTTPS_CERT_TUPLE]
        if not verify:
            verify = security_data[const.HTTPS_VERIFY_TUPLE]

        if not refresh and security_data[const.COOKIE_TUPLE]:
            return security_data[const.COOKIE_TUPLE], verify

        payload = {"aaaUser": {"attributes": {
                   "name": security_data[const.UNAME_TUPLE],
                   "pwd": security_data[const.PW_TUPLE]}}}
        headers = {"Content-type": "application/json", "Accept": "text/plain"}

        url = "{0}://{1}/api/aaaLogin.json".format(DEFAULT_SCHEME, mgmt_ip)

        try:
            response = self.session.request('POST',
                           url,
                           data=jsonutils.dumps(payload),
                           headers=headers,
                           verify=verify,
                           timeout=self.timeout * 2)
        except Exception as e:
            raise cexc.NexusConnectFailed(nexus_host=mgmt_ip,
                                         exc=e)

        self.status = response.status_code
        if response.status_code == requests.codes.OK:
            cookie = response.headers.get('Set-Cookie')
            security_data = (
                security_data[const.UNAME_TUPLE:const.COOKIE_TUPLE] +
                (cookie,))
            self.credentials[mgmt_ip] = security_data
            return cookie, verify
        else:
            e = "REST API connect returned Error code: "
            e += str(self.status)
            raise cexc.NexusConnectFailed(nexus_host=mgmt_ip,
                                         exc=e)