Python Spyne故障-HTTP返回代码

Python Spyne故障-HTTP返回代码,python,http,exception,spyne,Python,Http,Exception,Spyne,我已经阅读了有关Spyne Faults()的信息,但是我无法用400返回码正确地提出一个错误。我已经正确地形成了错误响应,但是当我需要返回400时,会使用500 HTTP返回代码 @srpc(Boolean, _returns=String) def requestConfiguration(value): #if value is true, get all the data if value == True: #todo - get the config

我已经阅读了有关Spyne Faults()的信息,但是我无法用400返回码正确地提出一个错误。我已经正确地形成了错误响应,但是当我需要返回400时,会使用500 HTTP返回代码

@srpc(Boolean, _returns=String)
def requestConfiguration(value):
    #if value is true, get all the data
    if value == True:
        #todo - get the config
        return 'True Received'

    else:
        # if anything other than True is received, MUST respond with a SOAP fault and HTTP 400
        raise Fault(faultcode="Client.", faultstring="Value must be True")
        # raise error.InvalidInputError("problem", "problem")
在阅读一些文档()时,我将其解释为FaultCode必须是以Client开头的字符串,它将返回400错误。(我知道如果还有其他不好的地方,我只是想在正确编写代码之前得到一个概念证明)

我想我需要对这个错误进行分类,而不是仅仅提出它,但我无法理解它。我深入研究了代码/protocol/soap/soap11,发现fault\u to\u http\u response\u代码只返回http 500


提前感谢

我放弃了子类方法,而只是更新了soap11.py中的fault_to_http_response_代码函数。这是一个恶心的补丁,但它做了我想要的工作

def fault_to_http_response_code(self, fault):
    from spyne.const.http import HTTP_400, HTTP_401, HTTP_404, HTTP_405, HTTP_413, HTTP_500
    from spyne.error import Fault, InternalError, ResourceNotFoundError, RequestTooLongError, RequestNotAllowed, InvalidCredentialsError
    if isinstance(fault, RequestTooLongError):
        return HTTP_413
    if isinstance(fault, ResourceNotFoundError):
        return HTTP_404
    if isinstance(fault, RequestNotAllowed):
        return HTTP_405
    if isinstance(fault, InvalidCredentialsError):
        return HTTP_401
    if isinstance(fault, Fault) and (fault.faultcode.startswith('Client.')
                                            or fault.faultcode == 'Client'):
        return HTTP_400

    return HTTP_500
然后我只是提出了一个正常的错误,错误代码以客户端开始

raise Fault(faultcode="Client.", faultstring="value must be True)
希望有人能拿出适当的方法来解决这个问题