大佬教程收集整理的这篇文章主要介绍了如何在 Python 中使用 Spyne 从两个不同元素读取具有相同名称的 Xml 属性,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Python 新手。我正在尝试使用 Python(版本 3.9.6)和 spyne-2.13.16 的第一个 SOAP 服务。在此服务中,我所做的只是读取 xml 负载并在 Json 中将其打印为输出
我不确定如何从具有相同名称的 SOAP 请求中的两个不同元素读取 xml 属性。我在下面附上了我的请求负载和响应负载。
我有两个元素“generation_time”和“expiration_time”。它们都具有相同的属性“时间戳”。我在输出中看到代码打印了 expire_time 的时间戳属性的值。有没有办法可以控制需要打印哪个?
这是我的项目结构:
@H_117_2@mypythonWS | |- 应用程序(模块) |- app.py |- 模型.py |from spyne import Application,rpc,serviceBase
from spyne.protocol.Json import Jsondocument
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
import model
class MyPythonservice(serviceBasE):
@rpc(model.Root,_returns=model.Root)
def getConfiguration(ctx,root):
return root
application = Application([MyPythonservice],'mypython.type.service',in_protocol=Soap11(),out_protocol=Jsondocument())
wsgi_app = WsgiApplication(application)
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.INFO)
logging.getLogger('spyne.protocol.xml').setLevel(logging.INFO)
logging.info("Listening to http://127.0.0.1:8000")
logging.info("wsdl is at: http://localhost:8000/?wsdl")
server = make_server('0.0.0.0',8000,wsgi_app)
server.serve_forever()
@H_861_20@model.py>
class MetaType(ComplexModel):
__type_name__ = 'MetaType'
_type_info = {
'generation_time': Unicode,'microtime': XmlAttribute(UnicodE),'timestamp': XmlAttribute(UnicodE),'expiration_time': Unicode
}
class Root (ComplexModel):
__type_name__ = 'root'
_type_info = {
'Meta': MetaType
}
请求:
<?xml version="1.0" enCoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLscheR_392_11845@a-instance" xmlns:xsd="http://www.w3.org/2001/XMLscheR_392_11845@a" xmlns:soap="http://scheR_392_11845@as.xmlsoap.org/soap/envelope/">
<soap:Body>
<getConfiguration>
<root>
<Meta>
<generation_time microtime="1623853142.0784710" timestamp="1623853142">06/16/2021 2:19:02 PM UTC</generation_time>
<expiration_time timestamp="1635085143">10/24/2021 2:19:02 PM UTC</expiration_time>
</Meta>
</root>
</getConfiguration>
</soap:Body>
</soap:Envelope>
回复:
{
"Meta": {
"generation_time": "06/16/2021 2:19:02 PM UTC","microtime": "1623853142.0784710","timestamp": "1635085143","expiration_time": "10/24/2021 2:19:02 PM UTC"
}
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的如何在 Python 中使用 Spyne 从两个不同元素读取具有相同名称的 Xml 属性全部内容,希望文章能够帮你解决如何在 Python 中使用 Spyne 从两个不同元素读取具有相同名称的 Xml 属性所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。