How to use the sparkpost.SparkPostException function in sparkpost

To help you get started, we’ve selected a few sparkpost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anymail / django-anymail / anymail / backends / sparkpost.py View on Github external
# SPARKPOST_API_KEY is optional - library reads from env by default
        self.api_key = get_anymail_setting('api_key', esp_name=self.esp_name,
                                           kwargs=kwargs, allow_bare=True, default=None)

        # SPARKPOST_API_URL is optional - default is set by library;
        # if provided, must be a full SparkPost API endpoint, including "/v1" if appropriate
        api_url = get_anymail_setting('api_url', esp_name=self.esp_name, kwargs=kwargs, default=None)
        extra_sparkpost_params = {}
        if api_url is not None:
            if api_url.endswith("/"):
                api_url = api_url[:-1]
            extra_sparkpost_params['base_uri'] = _FullSparkPostEndpoint(api_url)

        try:
            self.sp = SparkPost(self.api_key, **extra_sparkpost_params)  # SparkPost API instance
        except SparkPostException as err:
            # This is almost certainly a missing API key
            raise AnymailConfigurationError(
                "Error initializing SparkPost: %s\n"
                "You may need to set ANYMAIL = {'SPARKPOST_API_KEY': ...} "
                "or ANYMAIL_SPARKPOST_API_KEY in your Django settings, "
                "or SPARKPOST_API_KEY in your environment." % str(err)
            )