在python中使用zeep从wsdl文件中提取数据。

问题描述 投票:1回答:1

我有访问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.commvantellingenpython-zeepissues297#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 api soap wsdl zeep
1个回答
2
投票

感谢所要求的输出。

从定义。getDrugList(DRUGSTATUS: xsd:string) -> DRUGLIST: {DRUG: ns0:drug[]} 它看起来像方法 getDrugList 只接受1个类型为string &amp的参数;它返回一个列表,其中包括 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)

further if response 是一个有效的回应,那么 DRUGLIST 可使用 for 循环。

希望能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.