繁体   English   中英

requests.exceptions.HTTPError: 415 Client Error Unsupported Media Type when using python zeep

[英]requests.exceptions.HTTPError: 415 Client Error Unsupported Media Type when using python zeep

我正在使用 python zeep 来使用网络服务。 我使用过 SOAP UI,并且能够使用 Web 服务。 当我使用以下代码时,它会生成 HTTP 错误。 如何查看 SOAP 请求内容以实际检查我在请求中发送的内容。

class MyLoggingPlugin(Plugin):

    def ingress(self, envelope, http_headers, operation):
        return envelope, http_headers

    def egress(self, envelope, http_headers, operation, binding_options):
        http_headers['Content-Type'] = 'text/xml; charset=utf-8;'
        return envelope, http_headers

requests.packages.urllib3.disable_warnings()
session = Session()
session.verify = False
session.auth = HTTPBasicAuth('xxxxxxx', 'xxxxx')
client = 
Client('https://xxxx.com:44383/sap/bc/srt/rfc/sap/zws_send_emailid/101/zws_send_emailid/binding_1',
     transport=Transport(session=session),plugins=[MyLoggingPlugin()])

不确定您是否还需要答案。

您实际上可以修改您的插件以查看实际的 xml,如下所示:

from lxml import etree

class MyLoggingPlugin(Plugin):

    def ingress(self, envelope, http_headers, operation):
        # to see whats coming in
        print(etree.tostring(envelope, pretty_print=True))
        return envelope, http_headers

    def egress(self, envelope, http_headers, operation, binding_options):
        http_headers['Content-Type'] = 'text/xml; charset=utf-8;'
        # to see whats going out
        print(etree.tostring(envelope, pretty_print=True))
        return envelope, http_headers

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM