6

我正在使用 python zeep 库,我正在尝试向肥皂客户端发送请求,但我不断收到此错误:

ValueError:字符串类型不接受集合作为值

这是 WSDL 客户端的 XML 文件:

<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>

这是我的代码:

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)

我被这个错误困扰了很长时间。如果有人可以提供帮助,我将不胜感激。

4

2 回答 2

9

将它们作为命名参数传递给您的服务方法:

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

或者因为你有很多参数并且它们已经是一个字典:

result = client.service.SendSms(**parameters)
于 2018-04-25T21:05:50.853 回答
5

看这个例子:并参考--> 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))
于 2019-04-02T11:22:53.823 回答