How to use the zeep.exceptions.Fault function in zeep

To help you get started, we’ve selected a few zeep 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 cornershop / python-tbk / tests / test_zeep_client.py View on Github external
def test_request_server_exception(self, __):
        method = mock.Mock()
        method_name = "methodName"
        setattr(self.zeep_client.client.service, method_name, method)
        message = ""
        code = "soap:Server"
        method.side_effect = zeep.exceptions.Fault(message, code)

        with self.assertRaises(SoapServerException) as context:
            request = self.create_soap_request(method_name)
            self.zeep_client.request(request)
        self.assertEqual(context.exception.error, "Invalid amount")
        self.assertEqual(context.exception.code, 304)
github meyt / payit / payit / gateways / mellat.py View on Github external
'localTime': datetime.now().strftime('%H%M%S'),
                'additionalData': '',
                'callBackUrl': self.config['callback_url'],
                'payerId': 0,
            }
            result = client.service.bpPayRequest(**params)
            if not result:
                raise TransactionError('Mellat: invalid information. %s' % result)
            res = str(result).split(',')
            res_code = res[0]
            if int(res_code) == 0:
                transaction.id = res[1]
            else:
                raise TransactionError('Mellat: invalid information. %s' % res_code)

        except zeep_exceptions.Fault:
            raise TransactionError('Mellat: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
github meyt / payit / payit / gateways / asanpardakht.py View on Github external
params = {
                'merchantConfigurationID': self.config['merchant_config_id'],
                'encryptedRequest': self._get_encrypted_request(transaction)
            }

            result = client.service.RequestOperation(**params)
            if not result:
                raise TransactionError('AsanPardakht: invalid information.')

            if result[0:1] == '0':
                exploded_result = str(result).split(',')  # Should have two part [XX,YY]
                transaction.id = exploded_result[1]
            else:
                raise TransactionError('AsanPardakht: invalid information. code: %s' % str(result))

        except zeep_exceptions.Fault:
            raise TransactionError('AsanPardakht: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
github ilyaglow / remote-virtualbox / remotevbox / websession_manager.py View on Github external
def login(self, user, password):
        """Use IWebsessionManager to login and exit if credentials are false

        :param user: username (VBOX_USER from /etc/default/virtualbox)
        :param password: unix password of the supplied user on VirtualBox host
        """
        try:
            return self.service.IWebsessionManager_logon(user, password)

        except zeep.exceptions.Fault:
            raise WrongCredentialsError("Wrong credentials supplied")
github meyt / payit / payit / gateways / parsian.py View on Github external
'Amount': int(transaction.amount),
                'CallBackUrl': self.config['callback_url'],
            }
            result = client.service.SalePaymentRequest(requestData=data)
            token = result.Token
            status = int(result.Status)
            if token and status == 0:
                transaction.id = str(token)

            else:
                raise TransactionError('Parsian: %s-%s' % (
                    status,
                    self._response_message_map[str(status)]
                ))

        except zeep_exceptions.Fault:
            raise TransactionError('Parsian: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
github meyt / payit / payit / gateways / irankish.py View on Github external
'merchantId': self.config['merchant'],
                'invoiceNo': transaction.order_id,
                'paymentId': transaction.order_id,
                'specialPaymentId': transaction.order_id,
                'amount': int(transaction.amount),
                'description': '',
                'revertURL': self.config['callback_url'],
            }
            result = client.service.MakeToken(**params)
            token = result.token
            if token:
                transaction.id = token
            else:
                raise TransactionError('Irankish: invalid information.')

        except zeep_exceptions.Fault:
            raise TransactionError('Irankish: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
github mvantellingen / python-zeep / src / zeep / wsdl / bindings / soap.py View on Github external
)
        while subcode_element is not None:
            subcode_value_element = subcode_element.find(
                "soap-env:Value", namespaces=self.nsmap
            )
            subcode_qname = as_qname(
                subcode_value_element.text, subcode_value_element.nsmap, None
            )
            subcodes.append(subcode_qname)
            subcode_element = subcode_element.find(
                "soap-env:Subcode", namespaces=self.nsmap
            )

        # TODO: We should use the fault message as defined in the wsdl.
        detail_node = fault_node.find("soap-env:Detail", namespaces=self.nsmap)
        raise Fault(
            message=message,
            code=code,
            actor=None,
            detail=detail_node,
            subcodes=subcodes,
        )
github WhyNotHugo / django-afip / django_afip / models.py View on Github external
def authorize(self):
        """Send this ticket to AFIP for authorization."""
        request = self.__create_request_xml()
        request = self.__sign_request(request)
        request = b64encode(request).decode()

        client = clients.get_client("wsaa", self.owner.is_sandboxed)
        try:
            raw_response = client.service.loginCms(request)
        except Fault as e:
            if str(e) == "Certificado expirado":
                raise exceptions.CertificateExpired(str(e)) from e
            if str(e) == "Certificado no emitido por AC de confianza":
                raise exceptions.UntrustedCertificate(str(e)) from e
            raise exceptions.AuthenticationError(str(e)) from e
        response = etree.fromstring(raw_response.encode("utf-8"))

        self.token = response.xpath(self.TOKEN_XPATH)[0].text
        self.signature = response.xpath(self.SIGN_XPATH)[0].text

        self.save()
github mvantellingen / python-zeep / src / zeep / wsdl / bindings / soap.py View on Github external
fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(
                message="Unknown fault occured",
                code=None,
                actor=None,
                detail=etree_to_string(doc),
            )

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        raise Fault(
            message=get_text("faultstring"),
            code=get_text("faultcode"),
            actor=get_text("faultactor"),
            detail=fault_node.find("detail"),
        )