当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.TwilioRestException方法代码示例

本文整理汇总了Python中twilio.base.exceptions.TwilioRestException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TwilioRestException方法的具体用法?Python exceptions.TwilioRestException怎么用?Python exceptions.TwilioRestException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twilio.base.exceptions的用法示例。


在下文中一共展示了exceptions.TwilioRestException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_exception_is_logged_when_raised

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_exception_is_logged_when_raised(client, mocker, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        mock_send_verification = mocker.patch(
            "phone_verify.services.PhoneVerificationService.send_verification"
        )
        mock_logger = mocker.patch("phone_verify.services.logger")
        backend_cls = _get_backend_cls(backend)
        if (
            backend_cls == "nexmo.NexmoBackend"
            or backend_cls == "nexmo.NexmoSandboxBackend"
        ):
            exc = ClientError()
            mock_send_verification.side_effect = exc
        elif (
            backend_cls == "twilio.TwilioBackend"
            or backend_cls == "twilio.TwilioSandboxBackend"
        ):
            exc = TwilioRestException(status=mocker.Mock(), uri=mocker.Mock())
            mock_send_verification.side_effect = exc
        send_security_code_and_generate_session_token(phone_number="+13478379634")
        mock_logger.error.assert_called_once_with(
            f"Error in sending verification code to +13478379634: {exc}"
        ) 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:25,代码来源:test_services.py

示例2: post_receive

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def post_receive(self, alert):

        if alert.repeat:
            return

        message = "%s: %s alert for %s - %s is %s" % (
            alert.environment, alert.severity.capitalize(),
            ','.join(alert.service), alert.resource, alert.event
        )

        client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
        for twilio_to in TWILIO_TO_NUMBER.split(','):
            LOG.debug('Twilio SMS: Send message from {}, to {}'.format(TWILIO_FROM_NUMBER, twilio_to))
            try:
                message = client.messages.create(body=message, to=twilio_to, from_=TWILIO_FROM_NUMBER)
            except TwilioRestException as e:
                LOG.error('Twilio SMS: ERROR - {}'.format(str(e)))
            else:
                LOG.info("Twilio SMS: Message ID: %s", message.sid) 
开发者ID:alerta,项目名称:alerta-contrib,代码行数:21,代码来源:alerta_twilio_sms.py

示例3: _send_text

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def _send_text(self, recipient_id, text):
        from twilio.base.exceptions import TwilioRestException

        message = None
        try:
            while not message and self.send_retry < self.max_retry:
                message = self.messages.create(body=text,
                                               to=recipient_id,
                                               from_=self.twilio_number)
                self.send_retry += 1
        except TwilioRestException as e:
            logger.error("Something went wrong " + repr(e.msg))
        finally:
            self.send_retry = 0

        if not message and self.send_retry == self.max_retry:
            logger.error("Failed to send message. Max number of "
                         "retires exceeded.")

        return message 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:22,代码来源:twilio.py

示例4: form_valid

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def form_valid(self, form):
        try:
            with transaction.atomic():
                return super().form_valid(form)
        except TwilioRestException as e:
            if e.status >= 500:
                logger.exception(str(e))
                msg = TWILIO_ERRORS.get('default')
            else:
                msg = TWILIO_ERRORS.get(e.code)

            if msg:
                form.add_error('phone', msg)
                return self.form_invalid(form)
            else:
                raise 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:18,代码来源:default.py

示例5: test_update_invalid_phone

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_update_invalid_phone(self, send_sms):
        self.user.email = None
        self.user.phone = '+12345678990'
        self.user.phone_verified = True
        self.user.save()

        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Unable to create record: The "To" number +15555555555 is '
                 'not a valid phone number.'),
            method='POST',
            code=21211
        )
        data = {'phone': '+15555555555', 'username': 'imagine72'}
        response = self.request(method='PUT', post_data=data, user=self.user)
        assert response.status_code == 400
        assert TWILIO_ERRORS[21211] in response.content['phone']
        assert VerificationDevice.objects.filter(
            unverified_phone='+15555555555').exists() is False

        self.user.refresh_from_db()
        assert self.user.username != 'imagine72'
        assert self.user.phone == '+12345678990'
        assert self.user.phone_verified is True 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:27,代码来源:test_views_api.py

示例6: test_update_twilio_error_400

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_update_twilio_error_400(self, send_sms):
        self.user.email = None
        self.user.phone = '+12345678990'
        self.user.phone_verified = True
        self.user.save()

        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Account not active'),
            method='POST',
            code=20005
        )
        data = {'phone': '+15555555555', 'username': 'imagine72'}
        with pytest.raises(TwilioRestException):
            self.request(method='PUT', post_data=data, user=self.user)
        assert VerificationDevice.objects.filter(
            unverified_phone='+15555555555').exists() is False

        self.user.refresh_from_db()
        assert self.user.username != 'imagine72'
        assert self.user.phone == '+12345678990'
        assert self.user.phone_verified is True 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:25,代码来源:test_views_api.py

示例7: test_update_twilio_error_500

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_update_twilio_error_500(self, send_sms):
        self.user.email = None
        self.user.phone = '+12345678990'
        self.user.phone_verified = True
        self.user.save()

        send_sms.side_effect = TwilioRestException(
            status=500,
            uri='http://localhost:8000',
            msg=('Account not active'),
            method='POST',
            code=20005
        )
        data = {'phone': '+15555555555', 'username': 'imagine72'}
        response = self.request(method='PUT', post_data=data, user=self.user)
        assert response.status_code == 400
        assert TWILIO_ERRORS['default'] in response.content['phone']
        assert VerificationDevice.objects.filter(
            unverified_phone='+15555555555').exists() is False

        self.user.refresh_from_db()
        assert self.user.username != 'imagine72'
        assert self.user.phone == '+12345678990'
        assert self.user.phone_verified is True 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:26,代码来源:test_views_api.py

示例8: test_signup_invalid_phone

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_signup_invalid_phone(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Unable to create record: The "To" number +15555555555 is '
                 'not a valid phone number.'),
            method='POST',
            code=21211
        )
        data = {
            'username': 'sherlock',
            'email': '',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 400
        assert TWILIO_ERRORS[21211] in response.content['phone']
        assert VerificationDevice.objects.filter(
            unverified_phone='+15555555555').exists() is False
        assert User.objects.count() == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:24,代码来源:test_views_api.py

示例9: test_signup_twilio_error_400

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_signup_twilio_error_400(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Account not active'),
            method='POST',
            code=20005
        )
        data = {
            'username': 'sherlock',
            'email': '',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes'
        }
        with pytest.raises(TwilioRestException):
            self.request(method='POST', post_data=data)
        assert VerificationDevice.objects.filter(
            unverified_phone='+15555555555').exists() is False
        assert User.objects.count() == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:22,代码来源:test_views_api.py

示例10: test_sign_up_with_invalid_phone_number

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_sign_up_with_invalid_phone_number(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Unable to create record: The "To" number +15555555555 is '
                 'not a valid phone number.'),
            method='POST',
            code=21211
        )
        data = {
            'username': 'sherlock',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 200
        assert TWILIO_ERRORS[21211] in response.content
        assert User.objects.count() == 0
        assert VerificationDevice.objects.count() == 0
        assert len(mail.outbox) == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:24,代码来源:test_views_default.py

示例11: test_twilio_error_400

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_twilio_error_400(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Account not active'),
            method='POST',
            code=20005
        )
        data = {
            'username': 'sherlock',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        with pytest.raises(TwilioRestException):
            self.request(method='POST', post_data=data)
            assert User.objects.count() == 0
            assert VerificationDevice.objects.count() == 0
            assert len(mail.outbox) == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:22,代码来源:test_views_default.py

示例12: test_twilio_error_500

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_twilio_error_500(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=500,
            uri='http://localhost:8000',
            msg=('Account not active'),
            method='POST',
            code=20005
        )
        data = {
            'username': 'sherlock',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 200
        assert TWILIO_ERRORS['default'] in response.content
        self.request(method='POST', post_data=data)
        assert User.objects.count() == 0
        assert VerificationDevice.objects.count() == 0
        assert len(mail.outbox) == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:24,代码来源:test_views_default.py

示例13: test_update_profile_with_invalid_phone

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_update_profile_with_invalid_phone(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Unable to create record: The "To" number +15555555555 is '
                 'not a valid phone number.'),
            method='POST',
            code=21211
        )
        user = UserFactory.create(password='221B@bakerstreet')
        post_data = {
            'username': 'new_name',
            'email': user.email,
            'phone': '+919327768250',
            'language': 'en',
            'measurement': 'metric',
            'full_name': 'Sherlock Holmes',
            'password': '221B@bakerstreet'
        }
        response = self.request(method='POST', post_data=post_data, user=user)
        assert response.status_code == 200
        assert TWILIO_ERRORS[21211] in response.content
        assert VerificationDevice.objects.count() == 0
        user.refresh_from_db()
        assert user.username != 'new_name' 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:27,代码来源:test_views_default.py

示例14: test_send_token_with_invalid_phone

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def test_send_token_with_invalid_phone(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Unable to create record: The "To" number +15555555555 is '
                 'not a valid phone number.'),
            method='POST',
            code=21211
        )
        VerificationDevice.objects.create(user=self.user,
                                          unverified_phone=self.user.phone)
        data = {
            'phone': '+919327768250',
        }
        response = self.request(method='POST', post_data=data)

        assert response.status_code == 200
        assert TWILIO_ERRORS[21211] in response.content 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:20,代码来源:test_views_default.py

示例15: update

# 需要导入模块: from twilio.base import exceptions [as 别名]
# 或者: from twilio.base.exceptions import TwilioRestException [as 别名]
def update(self, request, *args, **kwargs):
        try:
            with transaction.atomic():
                return super().update(request, *args, **kwargs)
        except TwilioRestException as e:
            if e.status >= 500:
                logger.exception(str(e))
                msg = messages.TWILIO_ERRORS.get('default')
            else:
                msg = messages.TWILIO_ERRORS.get(e.code)

            if msg:
                return Response(status=400, data={'phone': msg})
            else:
                raise 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:17,代码来源:api.py


注:本文中的twilio.base.exceptions.TwilioRestException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。