Search code examples
pythonsoapsuds

Assertion Error with suds


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


Solution

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