2017-01-30 102 views
1

我想从官方的pip仓库中使用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 

从回溯,我的理解是什么错误,但我想不出什么原因造成的。有什么建议么?

注:此请求是俄罗斯邮政API请求,所有需要采取​​

+0

我还没有足够的信誉发表评论,但我发现皂液的库页上的这种情况。它是一个[bug](https://bitbucket.org/jurko/suds/issues/106/assertionerror) –

回答

0

我一段时间后,再次运行到这个问题,这似乎是与编码问题。我将CentOS上的语言环境设置为“ru_RU.utf-8”,一切开始正常。

0

这应该可以解决这个问题:

from suds import byte_str 
message = byte_str(message)