gpt4 book ai didi

python - Spyne/RPClib - 如何响应 ComplexModel?

转载 作者:行者123 更新时间:2023-11-28 22:01:55 26 4
gpt4 key购买 nike

我正在使用 SPYNE这是第一次,我对如何用我的 ComplexModel 做出回应有点困惑。

#service.py
class Status(ComplexModel):
statusCode = Integer
statusMsg = String

class ResponseData(ComplexModel):
status = Array(Status)
version = Integer

class SoapService(ServiceBase):
@rpc(String, _returns=ResponseData)
def doSomething(ctx, name):
# ...
# do something to get a django-model-object
obj_data = Servers.objects.get(host=name)
# put vars from the django-model-object into 'ResponseData' and nested 'Status'
# e.g. statusCode = 1, statusMsg = 'online', version = 1

""" experimental - status is not returned - version is 1:
obj_status = Status()
obj_status.statusCode = 1
obj_status.statusMsg = 'online'

retval = ResponseData()
retval.status = obj_status
retval.version = 1
"""
return retval

有人知道如何填充 ComplexModels 吗? docsexamples帮不了我。

最佳答案

我找到了解决方案。这里有一个小演示。

#service.py
class Status(ComplexModel):
statusCode = Integer
statusMsg = String

class ResponseData(ComplexModel):
status = Array(Status)
version = Integer

class SoapService(ServiceBase):
@rpc(String, _returns=ResponseData)
def doSomething(ctx, name):

obj_data = Servers.objects.get(host=name)
if obj_data.status:
my_statusCode = 1
my_statusMsg = 'online'
else:
my_statusCode = 0
my_statusMsg = 'offline'

retval = ResponseData()
retval.status = [{'statusCode': my_statusCode, 'statusMsg': my_statusMsg}]
retval.version = 1
return retval

关于python - Spyne/RPClib - 如何响应 ComplexModel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12461577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com