Python Zeep - HTTP状态415(没有可用内容)

问题描述 投票:0回答:1

您好我使用zeep消耗基于肥皂的Web服务,我继续得到HTTP状态415错误。我挖了一下并使用Pycharm Debugger,发现原因是:

'无法处理邮件,因为内容类型为''text / xml; charset = utf-8 XaSOfalw:rtt; ___ utmvmBfuwVEwB = yEnqIuCmRhw \'不是预期的类型\'text / xml;字符集= UTF-8 \ ''

内容类型有什么问题?以及如何在Zeep中更改它?

我刚刚创建了一个简单的测试代码,如下所示:

from zeep import Client

pretend_wsdl = 'https://pretendwsdl'
client = Client(wsdl=pretend_wsdl)

res = client.service.NameOfService()
print(res)

并得到此错误:

zeep.exceptions.TransportError:服务器返回HTTP状态415(没有可用内容)

python web-services soap zeep
1个回答
0
投票

我已经通过在zeep客户端使用plugins解决了这个问题。

我的代码看起来像这样:

from zeep import Client
from zeep import Plugin


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


pretend_wsdl = 'https://pretendwsdl.com'

client = Client(wsdl=pretend_wsdl, plugins=[MyLoggingPlugin()])

res = client.service.NameOfService()

print(res)

我发现它很奇怪,因为zeep的默认内容类型是text / xml;字符集= UTF-8;我正在使用的wsdl并不认为来自zeep的内容类型是text / xml;字符集= UTF-8;

所以我使用zeep插件将内容类型显式设置为text / xml;字符集= UTF-8;它令人惊讶地工作。

© www.soinside.com 2019 - 2024. All rights reserved.