gpt4 book ai didi

python - 在泡沫中添加一个属性

转载 作者:太空狗 更新时间:2023-10-29 22:08:27 25 4
gpt4 key购买 nike

我必须用 suds 和 Python 做 soap 请求

<soap:Body> 
<registerOrder>
<order merchantOrderNumber="" description="" amount="" currency="" language="" xmlns="">
<returnUrl>http://mysafety.com</returnUrl>
</order>
</registerOrder>
</soap:Body>

如何在registerOrder中添加一个属性?

最佳答案

一个更加动态的 MessagePlugin 版本是:

from suds.sax.attribute import Attribute
from suds.plugin import MessagePlugin

class _AttributePlugin(MessagePlugin):
"""
Suds plug-in extending the method call with arbitrary attributes.
"""
def __init__(self, **kwargs):
self.kwargs = kwargs

def marshalled(self, context):
method = context.envelope.getChild('Body')[0]
for key, item in self.kwargs.iteritems():
method.attributes.append(Attribute(key, item))

用法:

client = Client(url)
# method 1
client.options.plugins = [_AttributePlugin(foo='bar')]
response = client.service.method1()
client.options.plugins = []
# method 2
response = client.service.method2()

关于python - 在泡沫中添加一个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5588403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com