def __gen_req_header()

in wadebug/wa_actions/wabiz_api.py [0:0]


    def __gen_req_header(self):
        # encode(): string -> byte, to use in b64encode()
        # decode(): byte -> string, to use in header
        encoded = base64.b64encode(
            "{}:{}".format(self.api_user, self.api_password).encode()
        ).decode()
        try:
            res = requests.post(
                url=urljoin(self.api_baseUrl, self.LOGIN_USER_ENDPOINT),
                headers={"AUTHORIZATION": "Basic {}".format(encoded)},
                verify=False,  # disable ssl verification
            )
            if res.status_code == 401:
                raise exceptions.WABizAuthError(
                    "API authentication error.  Please check your "
                    "configuration file (wadebug.conf.yml "
                    "in current directory)."
                )

            res = res.json()
        except requests.exceptions.RequestException as e:
            raise exceptions.WABizNetworkError(
                "Network request error. Please check your "
                "configuration (wadebug.conf.yml in current directory)."
                "\n{}".format(e)
            )

        token = res["users"][0]["token"]
        return {
            "AUTHORIZATION": "Bearer {}".format(token),
            "CONTENT_TYPE": "application/json",
        }