简体   繁体   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

I am using python zeep for consuming a webservice.我正在使用 python zeep 来使用网络服务。 I had used SOAP UI and I am able to consume the webservice.我使用过 SOAP UI,并且能够使用 Web 服务。 when I am using the below code it generates HTTP Error.当我使用以下代码时,它会生成 HTTP 错误。 How can I see the SOAP request content to actually check what i am sending in the request.如何查看 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()])

Not sure if you still need the answer.不确定您是否还需要答案。

You can actually just modify your plugin to see the actual xml like this:您实际上可以修改您的插件以查看实际的 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

hope this helps.希望这可以帮助。

暂无
暂无

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

相关问题 requests.exceptions.HTTPError:400客户端错误:错误的url请求 - requests.exceptions.HTTPError: 400 Client Error: Bad Request for url 如何使用请求修复Python中的'415 Unsupported Media Type'错误 - How to fix '415 Unsupported Media Type' error in Python using requests requests.exceptions.HTTPError: 401 客户端错误 atlassian-python-api - requests.exceptions.HTTPError: 401 Client Error atlassian-python-api 尝试创建 CloudOCR 对象时出现“requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: ...” - "requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: ..." when trying to create CloudOCR object requests.exceptions.HTTPError:429 客户端错误:url 的请求太多 - requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url Python GET 请求 - 415 不支持的媒体类型 - Python GET requests - 415 unsupported media type 从 requests.exceptions.HTTPError 获取 HTTP 错误代码 - Get HTTP Error code from requests.exceptions.HTTPError requests.exceptions.HTTPError 与 requests.HTTPError - requests.exceptions.HTTPError vs requests.HTTPError requests.exceptions.HTTPError:400客户端错误:网址请求错误:https://accounts.spotify.com/api/token - requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token requests.exceptions.HTTPError:404 客户端错误:未找到 url:https://chat.meta.stackexchange.com/chats/1543/messages/new - requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://chat.meta.stackexchange.com/chats/1543/messages/new
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM