Ошибка assert msg.__class__ is suds.byte_str_class AssertionError
Помогите пожалуйста решить проблему,вот код:
from suds.client import Client
from suds.sudsobject import asdict
from suds.sax.text import Text
from openpyxl import load_workbook
import datetime
import json
class Excel_get():
def __init__(self):
self.wb = load_workbook('barcode.xlsx')
self.ws = self.wb.get_sheet_by_name("Sheet")
def get_barcode(self):
ws_kol = self.ws.max_row + 1
list_articl = []
for r in range(1, ws_kol):
c = self.ws.cell(row=r, column=1).value
list_articl.append(c)
return list_articl
class PoshtaPU():
def __init__(self, code):
self.url = 'https://tracking.russianpost.ru/rtm34?wsdl'
self.client = Client(self.url, headers={'Content-Type': 'application/soap+xml; charset=utf-8'})
self.barcode = code
self.my_login = 'login'
self.my_password = 'password'
def recursive_asdict(self,d):
out = {}
for k, v in asdict(d).items():
k = k.lower()
if hasattr(v, '__keylist__'):
out[k] = self.recursive_asdict(v)
elif isinstance(v, list):
out[k] = []
for item in v:
if hasattr(item, '__keylist__'):
out[k].append(self.recursive_asdict(item))
else:
out[k].append(
item.title() if isinstance(item, Text) else item)
else:
out[k] = v.title() if isinstance(v, Text) else v
return out
def get_result(self):
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>""" + self.barcode + """</data:Barcode>
<data:MessageType>0</data:MessageType>
<data:Language>RUS</data:Language>
</data:OperationHistoryRequest>
<data:AuthorizationHeader soapenv:mustUnderstand="1">
<data:login>""" + self.my_login + """</data:login>
<data:password>""" + self.my_password + """</data:password>
</data:AuthorizationHeader>
</oper:getOperationHistory>
</soap:Body>
</soap:Envelope>"""
result = self.client.service.getOperationHistory(__inject={'msg': message})
result_json = self.recursive_asdict(result)
print(result_json)
return result_json
def main():
# e = Excel_get()
# list_articl = e.get_barcode()
# for article in list_articl[:5]:
p = PoshtaPU('80086148106435')
p.get_result()
if __name__ == '__main__':
main()
Ошибка:File "C:/Users/Антон/PycharmProjects/doestmatter/venv/test_poshta.py", line 89, in main() File "C:/Users/Антон/PycharmProjects/doestmatter/venv/test_poshta.py", line 84, in main p.get_result() File "C:/Users/Антон/PycharmProjects/doestmatter/venv/test_poshta.py", line 74, in get_result result = self.client.service.getOperationHistory(inject={'msg': message}) File "C:\Users\Антон\PycharmProjects\doestmatter\venv\lib\site-packages\suds\client.py", line 521, in __call return client.invoke(args, kwargs) File "C:\Users\Антон\PycharmProjects\doestmatter\venv\lib\site-packages\suds\client.py", line 760, in invoke assert msg.class is suds.byte_str_class AssertionError