6

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.

peterh
  • 11,875
  • 18
  • 85
  • 108

2 Answers2

11

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)
Justin W
  • 1,315
  • 9
  • 14
  • 1
    that is a standard python operator for [unpacking](https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists) a dict into keyword arguments to the function. – Justin W Dec 20 '18 at 15:57
4

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))
Juraj Bezručka
  • 512
  • 5
  • 21
Eyasu
  • 240
  • 3
  • 13