鱼C论坛

 找回密码
 立即注册
查看: 1169|回复: 2

webservice接口定义数组形参,client调用时如何传参

[复制链接]
发表于 2020-4-23 16:37:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
小白的问题:
1、经过各种度娘查到,数组里形参可以使用复杂数据类型ComplexModel,代码如下

api.py

  1. from spyne import Application, rpc, ServiceBase, String, Integer, Float, Array,ComplexModel
  2. from spyne.protocol.soap import Soap11
  3. from spyne.server.wsgi import WsgiApplication
  4. # 将Spyne创建的app 发布为django
  5. from spyne.server.django import DjangoApplication
  6. from django.views.decorators.csrf import csrf_exempt
  7. import redis
  8. from data.enume import repayFund_dict, overdue_dict

  9. # Create your views here.

  10. r = redis.Redis(host='........', port=6379, decode_responses=True)


  11. class Detail(ComplexModel):
  12.     term = Integer
  13.     principal = Float
  14.     interest = Float
  15.     punishmoney = Float
  16.     service_money = Float


  17. class Repay(ServiceBase):
  18.     global res

  19.     @rpc(Integer, Integer, String, Integer, Integer, Integer, Float, Array(Detail), Float, Array(Detail), String,
  20.          _returns=String)
  21.     def RepayOverdue(self, collection_id, orderno_id, borrowid, is_normal, loan_from, is_already, repay_money, detail,
  22.                      write_off_money, write_off_detail, write_off_id):
  23.         if (not collection_id) or (not borrowid) or (not is_already) or (not repay_money) or (not detail):
  24.             res = '必填参数缺失'
  25.         elif borrowid in r.hkeys('overdue_fail_list'):
  26.             res = overdue_dict[r.hget('overdue_fail_list',borrowid)]
  27.         elif borrowid in r.hkeys('overdue_success_list'):
  28.             res = overdue_dict['3']
  29.         else:
  30.             if write_off_money > 0:
  31.                 if not write_off_detail:
  32.                     res = '必填参数缺失'
  33.                 else:
  34.                     r.hset('overdue_success_list', borrowid, 1)
  35.                     res = overdue_dict['1']
  36.             else:
  37.                 r.hset('overdue_success_list', borrowid, 1)
  38.                 res = overdue_dict['1']
  39.         print(detail)
  40.         return res


  41. # 命名空间 tns 传入类型Soap11() 传出类型Soap11()
  42. application = Application([Repay], tns='spyne.repay.soap', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())

  43. # 定义DjangoApplication
  44. item_app = csrf_exempt(DjangoApplication(application))

  45. if __name__ == '__main__':
  46.     import logging
  47.     from wsgiref.simple_server import make_server

  48.     # Wrap the Spyne application with its wsgi wrapper
  49.     wsgi_app = WsgiApplication(application)

  50.     logging.basicConfig(level=logging.DEBUG)
  51.     logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
  52.     logging.info("listening to http://127.0.0.1:8000")
  53.     logging.info("wsdl is at: http://localhost:8000/?wsdl")
  54.     server = make_server('127.0.0.1', 8000, wsgi_app)
  55.     server.serve_forever()
复制代码


2、使用python3的suds-py3模块进行访问,代码如下
client.py

  1. from suds.client import Client

  2. client = Client('http://127.0.0.1:8000/WebApi/?wsdl')

  3. detail = client.factory.create('DetailArray')
  4. detail.term = 0
  5. detail.principal = 500.00
  6. detail.interest = 200.00
  7. detail.punishmoney = 300.00
  8. detail.service_money = 0.00

  9. client.service.RepayOverdue(collection_id=111, orderno_id=222, borrowid='2791833', is_normal=1, loan_from=1,
  10.                             is_already=1, repay_money=20000.00, detail=detail,
  11.                             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),是不是一定要这么写
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-23 22:11:14 | 显示全部楼层
鱼佬,能不能给解答下,救济
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-25 12:34:49 | 显示全部楼层
没人会吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-16 11:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表