如何使用zeep发送xml请求?

问题描述

我正在努力了解如何使用python请求数据。我使用zeep在代码中实现了wsdl文件。我认为问题是正文请求,即xml格式。欢迎任何帮助!

from requests import Session
from zeep import Client,Settings
from zeep.transports import Transport

session = Session()
session.verify = ('my_pem_file.pem')
transport = Transport(session=session)
settings = Settings(strict=False,xml_huge_tree=True)
client = Client("my_wdsl_file.xml",transport=transport,settings=settings)


anfrage = '''<item>
               <NAME>VAR_NAME_1</NAME>
               <VALUE>/SIE/PD_VASHU004</VALUE>
            </item>'''

print(client.service.RRW3_GET_QUERY_VIEW_DATA("/SIE/PD_PFI21","",anfrage,"EPIQ_FINANCIALS"))

如果运行终端命令python -wzeep "my_wsdl_file.xml,则会得到以下方法定义:

ns0:RRW3_GET_QUERY_VIEW_DATA(I_INFOPROVIDER: ns0:char30,I_QUERY: ns0:char30,I_T_PARAMETER: ns0:RRXW3TQUERY,I_VIEW_ID: ns0:char30)

因此,我放置了char30提供程序,即空的char30查询,但我不知道如何转换xml正文请求以及特定格式是什么。

如果我像这样运行代码段,则会得到以下异常树。

Traceback (most recent call last):
  File "C:\Users\z0044r2t\Desktop\codeSAP.py",line 59,in <module>
    print(client.service.RRW3_GET_QUERY_VIEW_DATA("/SIE/PD_PFI21","EPIQ_FINANCIALS"))
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\proxy.py",line 40,in __call__
    return self._proxy._binding.send(
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\wsdl\bindings\soap.py",line 118,in send
    envelope,http_headers = self._create(
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\wsdl\bindings\soap.py",line 68,in _create
    serialized = operation_obj.create(*args,**kwargs)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\wsdl\definitions.py",line 215,in create
    return self.input.serialize(*args,**kwargs)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\wsdl\messages\soap.py",line 74,in serialize
    self.body.render(body,body_value)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\xsd\elements\element.py",line 231,in render
    self._render_value_item(parent,value,render_path)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\xsd\elements\element.py",line 255,in _render_value_item
    return self.type.render(node,None,render_path)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\xsd\types\complex.py",line 279,in render
    element.render(parent,element_value,child_path)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\xsd\elements\indicators.py",line 242,child_path)
  File "C:\Users\z0044r2t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\zeep\xsd\elements\element.py",line 229,in render
    element_value = value[name]
TypeError: string indices must be integers

解决方法

您是否可以共享运行python -mzeep的其余输出? ns0:RRXW3TQUERY类型的定义是什么?

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...