Assertion Error with suds

≯℡__Kan透↙ 提交于 2019-12-11 06:38:48

问题


I am trying to send some SOAP using suds by jurko (Python 3.5.2) from the official pip repository.

Here is my code. Unfortunately, I should hide my login and password, so you cannot just copy and paste it to your terminal.

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

And here I get an error:

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

From the traceback, I understand what the error is, but I cannot figure out what causes it. Any suggestions?

NOTE: this request is a Russian Post API request, all needed taken here


回答1:


I've run into this problem again after a while, and it seems to be a problem with encoding. I set locale on my CentOS to "ru_RU.utf-8" and everything started working.




回答2:


This should fix the issue:

from suds import byte_str
message = byte_str(message)


来源:https://stackoverflow.com/questions/41936558/assertion-error-with-suds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!