How to use the createsend.createsend.BadRequest function in createsend

To help you get started, we’ve selected a few createsend 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 campaignmonitor / createsend-python / test / test_subscriber.py View on Github external
def test_import_subscribers_complete_failure_because_of_bad_request(self):
        # Stub request with 400 Bad Request as the expected response status
        self.subscriber.stub_request(
            "subscribers/%s/import.json" % self.list_id, "custom_api_error.json", 400)
        subscribers = [
            {"EmailAddress": "example+1@example", "Name": "Example One"},
            {"EmailAddress": "example+2@example.com", "Name": "Example Two"},
            {"EmailAddress": "example+3@example.com", "Name": "Example Three"},
        ]
        self.assertRaises(
            BadRequest, self.subscriber.import_subscribers, self.list_id, subscribers, True)
github campaignmonitor / createsend-python / lib / createsend / subscriber.py View on Github external
def import_subscribers(self, list_id, subscribers, resubscribe, queue_subscription_based_autoresponders=False, restart_subscription_based_autoresponders=False):
        """Imports subscribers into a subscriber list."""
        body = {
            "Subscribers": subscribers,
            "Resubscribe": resubscribe,
            "QueueSubscriptionBasedAutoresponders": queue_subscription_based_autoresponders,
            "RestartSubscriptionBasedAutoresponders": restart_subscription_based_autoresponders}
        try:
            response = self._post("/subscribers/%s/import.json" %
                                  list_id, json.dumps(body))
        except BadRequest as br:
            # Subscriber import will throw BadRequest if some subscribers are not imported
            # successfully. If this occurs, we want to return the ResultData property of
            # the BadRequest exception (which is of the same "form" as the response we'd
            # receive upon a completely successful import)
            if hasattr(br.data, 'ResultData'):
                return br.data.ResultData
            else:
                raise br
        return json_to_py(response)