|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小白的问题:
1、经过各种度娘查到,数组里形参可以使用复杂数据类型ComplexModel,代码如下
api.py
from spyne import Application, rpc, ServiceBase, String, Integer, Float, Array,ComplexModel
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
# 将Spyne创建的app 发布为django
from spyne.server.django import DjangoApplication
from django.views.decorators.csrf import csrf_exempt
import redis
from data.enume import repayFund_dict, overdue_dict
# Create your views here.
r = redis.Redis(host='........', port=6379, decode_responses=True)
class Detail(ComplexModel):
term = Integer
principal = Float
interest = Float
punishmoney = Float
service_money = Float
class Repay(ServiceBase):
global res
@rpc(Integer, Integer, String, Integer, Integer, Integer, Float, Array(Detail), Float, Array(Detail), String,
_returns=String)
def RepayOverdue(self, collection_id, orderno_id, borrowid, is_normal, loan_from, is_already, repay_money, detail,
write_off_money, write_off_detail, write_off_id):
if (not collection_id) or (not borrowid) or (not is_already) or (not repay_money) or (not detail):
res = '必填参数缺失'
elif borrowid in r.hkeys('overdue_fail_list'):
res = overdue_dict[r.hget('overdue_fail_list',borrowid)]
elif borrowid in r.hkeys('overdue_success_list'):
res = overdue_dict['3']
else:
if write_off_money > 0:
if not write_off_detail:
res = '必填参数缺失'
else:
r.hset('overdue_success_list', borrowid, 1)
res = overdue_dict['1']
else:
r.hset('overdue_success_list', borrowid, 1)
res = overdue_dict['1']
print(detail)
return res
# 命名空间 tns 传入类型Soap11() 传出类型Soap11()
application = Application([Repay], tns='spyne.repay.soap', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
# 定义DjangoApplication
item_app = csrf_exempt(DjangoApplication(application))
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
# Wrap the Spyne application with its wsgi wrapper
wsgi_app = WsgiApplication(application)
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.info("listening to http://127.0.0.1:8000")
logging.info("wsdl is at: http://localhost:8000/?wsdl")
server = make_server('127.0.0.1', 8000, wsgi_app)
server.serve_forever()
2、使用python3的suds-py3模块进行访问,代码如下
client.py
from suds.client import Client
client = Client('http://127.0.0.1:8000/WebApi/?wsdl')
detail = client.factory.create('DetailArray')
detail.term = 0
detail.principal = 500.00
detail.interest = 200.00
detail.punishmoney = 300.00
detail.service_money = 0.00
client.service.RepayOverdue(collection_id=111, orderno_id=222, borrowid='2791833', is_normal=1, loan_from=1,
is_already=1, repay_money=20000.00, detail=detail,
write_off_money=1000, write_off_detail='', write_off_id='333')
3、报错
(DetailArray) not-found
path: "DetailArray", not-found
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/lianxi/testApi.py", line 5, in <module>
detail = client.factory.create('DetailArray')
File "C:\Users\Administrator\PycharmProjects\lianxi\venv\lib\site-packages\suds\client.py", line 251, in create
raise TypeNotFound(name)
suds.TypeNotFound: Type not found: 'DetailArray'
请问大佬,要怎么解决?我这是模仿网上例子去写的,不明白client.factory.create()里面传的具体要求,形式,目前是复杂类型+Array组合(DetailArray),是不是一定要这么写
|
|