Saeed ALSferi
Saeed ALSferi

Reputation: 67

retrive data from wsdl file using zeep in python

i have access to wsdl file and i need to get in response a list of drug

but i get stuck with it and here my try


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'])

it give me this error

zeep.exceptions.Fault: 80210

and when i remove the parameter from

r = cl.service.getDrugList()

it give me this error

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

update

--

after Mr.@Tarique request

according to this link https://github.com/mvantellingen/python-zeep/issues/297#issuecomment-271803117 i use the same command and give me the same output for mzssp wsdl linke because i find a problem with auth and here the result


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



Upvotes: 1

Views: 2206

Answers (1)

Tarique
Tarique

Reputation: 1461

Thanks for the requested output.

from the definition: getDrugList(DRUGSTATUS: xsd:string) -> DRUGLIST: {DRUG: ns0:drug[]} it looks like method getDrugList is taking just 1 argument of type string & it returns a list of drug items.

you are passing an argument 'DRUGSTATUS' which I am not sure is a valid acceptable status by the service:

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

You should call the method like this:

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 is a valid response then DRUGLIST can be printed using a for loop.

hope this helps

Upvotes: 2

Related Questions