pythonsoapwsdlzeep

'Client' object has no attribute in zeep python wsdl


I defined a class for SMS sending in Python, then tried to use the 'getCredit' method and it worked. But it shows a warning while it is working:

UserWarning: The wsdl:message for '{urn:SMSwsdl}sendSMSRequest' contains an invalid part ('to'): invalid xsd type or elements UserWarning: The wsdl:message for '{urn:SMSwsdl}sendMultiSMSRequest' contains an invalid part ('to'): invalid xsd type or elements UserWarning: The wsdl:operation 'sendSMS' was not found in the wsdl:portType '{urn:SMSwsdl}SMSwsdlPortType' UserWarning: The wsdl:operation 'sendMultiSMS' was not found in the wsdl:portType '{urn:SMSwsdl}SMSwsdlPortType'

While I tried the 'sendSMS' method as follows:

def sendSMS(self, receiver, text):
        response = self.client.service.sendSMS(self.domain, self.username, self.password,
                                                self.number, receiver, text, 1)
        print(response)

I faced this error:

AttributeError: Service has no operation 'sendSMS'

and also this is the response to python3 -m zeep <wsd_url> :

Prefixes:
     xsd: http://www.w3.org/2001/XMLSchema
     ns0: urn:SMSwsdl
     ns1: http://schemas.xmlsoap.org/soap/encoding/

Global elements:
     ns1:Array(ns1:Array)
     ns1:ENTITIES(ns1:ENTITIES)
     ns1:ENTITY(ns1:ENTITY)
     ns1:ID(ns1:ID)
     ns1:IDREF(ns1:IDREF)
     ns1:IDREFS(ns1:IDREFS)
     ns1:NCName(ns1:NCName)
     ns1:NMTOKEN(ns1:NMTOKEN)
     ns1:NMTOKENS(ns1:NMTOKENS)
     ns1:NOTATION(ns1:NOTATION)
     ns1:Name(ns1:Name)
     ns1:QName(ns1:QName)
     ns1:Struct(ns1:Struct)
     ns1:anyType(xsd:anyType)
     ns1:anyURI(ns1:anyURI)
     ns1:base64Binary(ns1:base64Binary)
     ns1:boolean(ns1:boolean)
     ns1:byte(ns1:byte)
     ns1:date(ns1:date)
     ns1:dateTime(ns1:dateTime)
     ns1:decimal(ns1:decimal)
     ns1:double(ns1:double)
     ns1:duration(ns1:duration)
     ns1:float(ns1:float)
     ns1:gDay(ns1:gDay)
     ns1:gMonth(ns1:gMonth)
     ns1:gMonthDay(ns1:gMonthDay)
     ns1:gYear(ns1:gYear)
     ns1:gYearMonth(ns1:gYearMonth)
     ns1:hexBinary(ns1:hexBinary)
     ns1:int(ns1:int)
     ns1:integer(ns1:integer)
     ns1:language(ns1:language)
     ns1:long(ns1:long)
     ns1:negativeInteger(ns1:negativeInteger)
     ns1:nonNegativeInteger(ns1:nonNegativeInteger)
     ns1:nonPositiveInteger(ns1:nonPositiveInteger)
     ns1:normalizedString(ns1:normalizedString)
     ns1:positiveInteger(ns1:positiveInteger)
     ns1:short(ns1:short)
     ns1:string(ns1:string)
     ns1:time(ns1:time)
     ns1:token(ns1:token)
     ns1:unsignedByte(ns1:unsignedByte)
     ns1:unsignedInt(ns1:unsignedInt)
     ns1:unsignedLong(ns1:unsignedLong)
     ns1:unsignedShort(ns1:unsignedShort)


Global types:
     xsd:anyType
     ns1:Array(_value_1: ANY[], arrayType: xsd:string, offset: ns1:arrayCoordinate, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:ENTITIES(xsd:ENTITIES, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:ENTITY(xsd:ENTITY, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:ID(xsd:ID, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:IDREF(xsd:IDREF, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:IDREFS(xsd:IDREFS, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:NCName(xsd:NCName, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:NMTOKEN(xsd:NMTOKEN, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:NMTOKENS(xsd:NMTOKENS, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:NOTATION(xsd:QName, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:Name(xsd:Name, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:QName(xsd:QName, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:Struct(_value_1: ANY[], id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:anyURI(xsd:anyURI, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:arrayCoordinate
     ns1:base64
     ns1:base64Binary(xsd:base64Binary, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:boolean(xsd:boolean, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:byte(xsd:byte, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:date(xsd:date, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:dateTime(xsd:dateTime, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:decimal(xsd:decimal, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:double(xsd:double, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:duration(xsd:duration, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:float(xsd:float, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:gDay(xsd:gDay, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:gMonth(xsd:gMonth, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:gMonthDay(xsd:gMonthDay, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:gYear(xsd:gYear, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:gYearMonth(xsd:gYearMonth, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:hexBinary(xsd:hexBinary, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:int(xsd:int, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:integer(xsd:integer, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:language(xsd:language, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:long(xsd:long, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:negativeInteger(xsd:negativeInteger, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:nonNegativeInteger(xsd:nonNegativeInteger, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:nonPositiveInteger(xsd:nonPositiveInteger, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:normalizedString(xsd:normalizedString, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:positiveInteger(xsd:positiveInteger, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:short(xsd:short, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:string(xsd:string, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:time(xsd:time, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:token(xsd:token, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:unsignedByte(xsd:unsignedByte, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:unsignedInt(xsd:unsignedInt, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:unsignedLong(xsd:unsignedLong, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns1:unsignedShort(xsd:unsignedShort, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     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
     ns0:account(acc_id: xsd:string, title: xsd:string)
     ns0:array_account(_value_1: account[], arrayType: xsd:string, offset: ns1:arrayCoordinate, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns0:array_delivery(_value_1: delivery[], arrayType: xsd:string, offset: ns1:arrayCoordinate, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns0:array_msg(_value_1: message[], arrayType: xsd:string, offset: ns1:arrayCoordinate, id: xsd:ID, href: xsd:anyURI, _attr_1: {})
     ns0:delivery(mobile: xsd:string, status: xsd:int)
     ns0:message(box: xsd:string, text: xsd:string, sms_id: xsd:int, send_date: xsd:string, credit: xsd:string, line_no: xsd:string, mobile_no: xsd:string)

Bindings:
     Soap11Binding: {urn:SMSwsdl}SMSwsdlBinding

Service: SMSwsdl
     Port: SMSwsdlPort (Soap11Binding: {urn:SMSwsdl}SMSwsdlBinding)
         Operations:
            checkReceive(mobile_no: xsd:string, text: xsd:string, line_number: xsd:string, domain: xsd:string, username: xsd:string, password: xsd:string) -> result: xsd:string, status: xsd:string
            getCredit(domain: xsd:string, username: xsd:string, password: xsd:string) -> return: xsd:string
            getCreditPrice(domain: xsd:string, username: xsd:string, password: xsd:string, amount: xsd:string) -> result: xsd:string, price: xsd:int
            getDelivery(domain: xsd:string, username: xsd:string, password: xsd:string, id: xsd:int) -> result: ns0:array_delivery
            getDeliveryMulti(domain: xsd:string, username: xsd:string, password: xsd:string, id: xsd:int) -> result: ns0:array_delivery
            getMessages(domain: xsd:string, username: xsd:string, password: xsd:string, smsType: xsd:string, start: xsd:string, count: xsd:string, from: xsd:string) -> result: ns0:array_msg
            getMessagesCount(domain: xsd:string, username: xsd:string, password: xsd:string, smsType: xsd:string, from: xsd:string, box: xsd:string) -> return: xsd:string
            getPayAccounts(domain: xsd:string, username: xsd:string, password: xsd:string) -> result: xsd:string, accounts: ns0:array_account
            payRequest(domain: xsd:string, username: xsd:string, password: xsd:string, account: xsd:string, amount: xsd:string, r_url: xsd:string) -> result: xsd:string, pay_id: xsd:int, url: xsd:string
            removeMessage(domain: xsd:string, username: xsd:string, password: xsd:string, ids: xsd:string, smsType: xsd:string) -> return: xsd:string

I searched and tried this method, but it didn't work:

Zeep client throws Service has no operation error


Solution

  • I got from this link that I can use the request library as well:

    def sendSMS(self, receiver, text):
        
        headers = {'Content-Type': 'text/xml; charset=utf-8',
                    'SOAPAction': 'urn:SMSwsdl#SMS'}
        
        body = f"""<?xml version="1.0" encoding="utf-8"?>
                <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                <soap:Body>
                    <sendSMSRequest>
                    <domain>{self.domain}</domain>
                    <username>{self.username}</username>
                    <password>{self.password}</password>
                    <from>{self.number}</from>
                    <to>{receiver}</to>
                    <text>{text}</text>
                    <isflash>1</isflash>
                    </sendSMSRequest>
                </soap:Body>
                </soap:Envelope>"""
        response = requests.post(wsdlURL,data=body.encode('utf-8'),headers=headers)
        print(response)