Amir ehsan Mohebi
Amir ehsan Mohebi

Reputation: 85

how to send parameters in zeep client

I am using python zeep library and I am trying to send a request to a soap client, but I keep getting this error:

ValueError: The String type doesn't accept collections as value

This is the XML file of the WSDL client:

<s:element name="SendSms">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="to" type="tns:ArrayOfString"/>
<s:element minOccurs="0" maxOccurs="1" name="from" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="text" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="isflash" type="s:boolean"/>
<s:element minOccurs="0" maxOccurs="1" name="udh" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="recId" type="tns:ArrayOfLong"/>
<s:element minOccurs="0" maxOccurs="1" name="status" type="s:base64Binary"/>
</s:sequence>
</s:complexType>
</s:element>

and here is my code:

from zeep import Client


client = Client("http://www.parandsms.ir/post/send.asmx?wsdl")
parameters = {
    "username":"my_user_name",
    "password":"my_password",
    "from":"50009666096096",
    "to":"a_phone_number_wich_i_put_here_as_string",
    "text":"salam",
    "isflash":False,
    'recId':"",

}
res = Client
status = 0
status= client.service.SendSms(parameters).SendSmsResult()
print(status)

I have been stuck at this error for a long time. If somebody could help I would really appreciate it.

Upvotes: 6

Views: 18287

Answers (2)

Eyasu Tewodros
Eyasu Tewodros

Reputation: 275

Look at this example: and refer--> https://chillyfacts.com/send-soap-request-and-read-xml-response-from-php-page/#respond

from zeep import Client
cl = Client('http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl')
request_data = {
    'countryCode': 'Scotland',
    'year': 2018}
print(cl.service.GetHolidaysForYear(**request_data))

Upvotes: 4

Justin W
Justin W

Reputation: 1315

Pass them as named parameters to your service method:

result = client.service.SendSms(username='my_user_name', password='my_password', ...)

or since you have many parameters and they're a dict already:

result = client.service.SendSms(**parameters)

Upvotes: 11

Related Questions