【问题标题】:retrive data from wsdl file using zeep in python在 python 中使用 zeep 从 wsdl 文件中检索数据
【发布时间】:2020-05-03 14:22:35
【问题描述】:

我可以访问 wsdl 文件,我需要得到一份药物清单

但我被它困住了,我在这里尝试


from zeep import Client
from requests.auth import HTTPBasicAuth  
from requests import Session
from zeep.transports import Transport

username = 'username'
password = 'password'
wsdl = 'wsdl link'

session = Session()
session.auth = HTTPBasicAuth(username, password)
cl = Client(wsdl,transport=Transport(session=session))
r = cl.service.getDrugList('DRUGSTATUS')
print(r['DRUGSTATUS'])

它给了我这个错误

zeep.exceptions.Fault: 80210

当我从

中删除参数时
r = cl.service.getDrugList()

它给了我这个错误

raise exceptions.ValidationError(
zeep.exceptions.ValidationError: Missing element DRUGSTATUS (DrugListServiceRequest.DRUGSTATUS)

更新

--

在@Tarique 先生请求之后

根据这个链接 https://github.com/mvantellingen/python-zeep/issues/297#issuecomment-271803117 我使用相同的命令并为 mzssp wsdl linke 提供相同的输出,因为我发现 auth 有问题,这里是结果


Prefixes:
    xsd: http://www.w3.org/2001/XMLSchema
    ns0: http://org linke/DrugListService

Global elements:
    ns0:DrugListServiceRequest(ns0:drugListServiceRequest)
    ns0:DrugListServiceRequestType(ns0:drugListServiceRequest)
    ns0:DrugListServiceResponse(ns0:drugListServiceResponse)
    ns0:DrugListServiceResponseType(ns0:drugListServiceResponse)
    ns0:ServiceError(ns0:faultBean)
    ns0:drug(ns0:drug)
    ns0:supplier(ns0:supplier)


Global types:
    xsd:anyType
    ns0:drug(GTIN: xsd:string, DRUGNAME: xsd:string, DOMAINID: xsd:short, LEGALSTATUS: xsd:short, MARKETINGSTATUS: xsd:short, DRUGSTATUS: xsd:short, SUPPLIERLIST: {SUPPLIER: ns0:supplier[]}, ISIMPORTABLE: xsd:short, ISEXPORTABLE: xsd:short, REGISTRATIONNUMBER: xsd:string, GENERICNAME: xsd:string, PRICE: xsd:decimal, DOSAGEFORM: xsd:string, PACKAGESIZE: xsd:string, PACKAGETYPE: xsd:string, STRENGTHVALUE: xsd:string, STRENGTHVALUEUNIT: xsd:string, VOLUME: xsd:string, UNITOFVOLUME: xsd:string)
    ns0:drugListServiceRequest(DRUGSTATUS: xsd:string)
    ns0:drugListServiceResponse(DRUGLIST: {DRUG: ns0:drug[]})
    ns0:faultBean(FC: xsd:string)
    ns0:supplier(GLN: xsd:string, SUPPLIERNAME: xsd:string)
    xsd:ENTITIES
    xsd:ENTITY
    xsd:ID
    xsd:IDREF
    xsd:IDREFS
    xsd:NCName
    xsd:NMTOKEN
    xsd:NMTOKENS
    xsd:NOTATION
    xsd:Name
    xsd:QName
    xsd:anySimpleType
    xsd:anyURI
    xsd:base64Binary
    xsd:boolean
    xsd:byte
    xsd:date
    xsd:dateTime
    xsd:decimal
    xsd:double
    xsd:duration
    xsd:float
    xsd:gDay
    xsd:gMonth
    xsd:gMonthDay
    xsd:gYear
    xsd:gYearMonth
    xsd:hexBinary
    xsd:int
    xsd:integer
    xsd:language
    xsd:long
    xsd:negativeInteger
    xsd:nonNegativeInteger
    xsd:nonPositiveInteger
    xsd:normalizedString
    xsd:positiveInteger
    xsd:short
    xsd:string
    xsd:time
    xsd:token
    xsd:unsignedByte
    xsd:unsignedInt
    xsd:unsignedLong
    xsd:unsignedShort

Bindings:
    Soap11Binding: {http://org linke/DrugListService}DrugListServiceBinding

Service: DrugListService
    Port: DrugListService (Soap11Binding: {http://org linke/DrugListService}DrugListServiceBinding)
        Operations:
           getDrugList(DRUGSTATUS: xsd:string) -> DRUGLIST: {DRUG: ns0:drug[]}

None



【问题讨论】:

  • 请运行:python -mzeep wsdl_link 然后粘贴getDrugList() 方法的定义。那么我们将能够以更好的方式为您提供帮助。
  • 你能检查一下先生吗? @Tarique 在主帖中。谢谢。

标签: python api soap wsdl zeep


【解决方案1】:

感谢您要求的输出。

根据定义:getDrugList(DRUGSTATUS: xsd:string) -> DRUGLIST: {DRUG: ns0:drug[]} 看起来方法 getDrugList 仅采用 1 个字符串类型的参数并返回 drug 项目列表。

您正在传递一个参数“DRUGSTATUS”,我不确定它是否是服务可接受的有效状态:

r = cl.service.getDrugList('DRUGSTATUS')

你应该这样调用方法:

r = cl.service.getDrugList(DRUGSTATUS='some_status')
# where some_status is valid DRUGSTATUS string. It could be found in service docs or examples.

# then check the response status & content:
print(r.status_code)
print(r.content)

如果response 是有效响应,则可以使用for 循环打印DRUGLIST

希望对你有帮助

【讨论】:

  • 在我的情况下我也有相同的查询有多个参数,请帮助我Ib440ConfigSet(NodeName: xsd:string, NodeDetail: ns0:NodeProperty, Ib440Details: ns0:Ib440DetailsSetWs, Ib440SnmpDetail: ns0:SnmpDetailSetWs, _soapheaders={Credentials: ns0:Credentials}) -> Ib440ConfigSetResult: ns0:NodeActionResult
猜你喜欢
  • 1970-01-01
  • 2018-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多