泡沫断言错误

Assertion Error with suds

我正在尝试从官方 pip 存储库发送一些使用 suds by jurko (Python 3.5.2) 的 SOAP。

这是我的代码。不幸的是,我应该隐藏我的登录名和密码,所以你不能只是将它复制并粘贴到你的终端。

my_login = 'login'
my_password = 'password'
barcode = '10100082848426'
message = \
                """<?xml version="1.0" encoding="UTF-8"?>
                                <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:oper="http://russianpost.org/operationhistory" xmlns:data="http://russianpost.org/operationhistory/data" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                                <soap:Header/>
                                <soap:Body>
                                   <oper:getOperationHistory>
                                      <data:OperationHistoryRequest>
                                         <data:Barcode>""" + barcode+ """</data:Barcode>
                                         <data:MessageType>0</data:MessageType>
                                         <data:Language>RUS</data:Language>
                                      </data:OperationHistoryRequest>
                                      <data:AuthorizationHeader soapenv:mustUnderstand="1">
                                         <data:login>"""+ my_login +"""</data:login>
                                         <data:password>""" + my_password + """</data:password>
                                      </data:AuthorizationHeader>
                                   </oper:getOperationHistory>
                                </soap:Body>
                             </soap:Envelope>"""
result = client.service.getOperationHistory(__inject={'msg':message})

这里我得到一个错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/suds/client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "/usr/local/lib/python3.5/site-packages/suds/client.py", line 760, in invoke
    assert msg.__class__ is suds.byte_str_class
AssertionError

从回溯中,我知道错误是什么,但我无法弄清楚是什么原因造成的。有什么建议吗?

注意:此请求是俄语 Post API 请求,所有需要的都已采纳 here

过段时间又运行遇到这个问题,好像是编码的问题。我在我的 CentOS 上将语言环境设置为 "ru_RU.utf-8",一切都开始工作了。

这应该可以解决问题:

from suds import byte_str
message = byte_str(message)