首页 > 解决方案 > 从命令行传递给 SOAP 参数

问题描述

我有一个成功发送 SOAP 以将记录插入系统的 python 脚本。这些值在测试中是静态的。我需要使通过命令行或其他存储值传递的值动态/参数。

执行:python myscript.py

<d4p1:Address>MainStreet</d4p1:Address>....这可以添加硬编码的“MainStreet”

执行:python myscript.py MainStreet

...这现在正在尝试传递参数 MainStreet

<d4p1:Address>sys.argv[1]</d4p1:Address> ....这不起作用

它将文字文本地址保存为“sys.argv[1]”......我已经导入了 sys ..我已经从网络搜索中尝试了 %、{} 等,我缺少什么语法?

标签: pythonxmlsoap

解决方案


You need to read a little about how to create strings in Python, below is how it could look like in your code. Sorry it's hard to say more without seeing your actual code. And you actually shouldn't create XMLs like that, you should use for instance xml module from standard library.

test = "<d4p1:Address>" + sys.argv[1] + "</d4p1:Address>"

推荐阅读