Python调取wsdl

96
CoderPoet
2017.06.04 01:53* 字数 163

首先解决一个报错问题:
pip install suds 报错:Traceback (most recent call last): File "setup.py", line 20, in <module> import suds File "/root/python-suds-0.4.1/suds/__init__.py", line 154, in <module> import client ImportError: No module named client
原因:版本兼容问题,suds类库语法上只兼容python2.7以下的版本,官网用sudo-jurko替代了

安装类库

pip install suds-jurko

调取wsdl接口代码实现

from django.shortcuts import render from django.http import HttpResponse from . import models from suds.client import Client def camds(request): url = '****?wsdl' client = Client(url) res = client.service.downloadMds(username,password,'CA_5_25523907', '****') return render(request, 'blog/camds.html', {'res': res})

用web.py框架实现

from suds.client import Client
import web
urls = (
        '/(.*)', 'Camds'
)
  app = web.application(urls, globals())


  class Camds:
      def GET(self, mds_id):
        url = '****?wsdl'
        client = Client(url)

    # 一些默认值
    username = '***'
    password = '***'
    key = '***'

    if not mds_id:
        return '请输入mds_id'

    res = client.service.downloadMds(username, password, mds_id, key)
    return res

  if __name__ == "__main__":
  app.run()`
记录
Web note ad 1