【发布时间】:2017-09-21 16:23:20
【问题描述】:
我编写了以下成功执行的代码。但是,我想将username 作为参数传递,而不是直接在内部硬编码
肥皂体。
import requests
url = "url?WSDL"
headers = {"Content-Type": "text/xml;charset=UTF-8"}
body = """<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header>
<tem:Authentication>
<!--Optional:-->
<tem:UserName>username</tem:UserName>
<!--Optional:-->
<tem:Password>password</tem:Password>
</tem:Authentication>
</soapenv:Header>
<soapenv:Body>
<tem:func1>
<!--Optional:-->
<tem:incident_number>INC000005215731</tem:incident_number>
<!--Optional:-->
<tem:wii>
<tem:Submitted>false</tem:Submitted>
<tem:Work_Info_Type>General_Information</tem:Work_Info_Type>
<!--Optional:-->
<tem:Summary>test</tem:Summary>
</tem:wii>
</tem:func1>
</soapenv:Body>
</soapenv:Envelope>"""
response = requests.post(url, data=body, headers=headers)
print response.content
另外,如何使用suds 转换上述代码?
到目前为止,我已经编写了以下代码:
from suds.client import Client
import logging
client = Client("url?WSDL")
user = client.factory.create('Authentication')
user['UserName'] = 'username'
user['Password'] = 'password'
client.set_options(soapheaders=user)
【问题讨论】:
标签: python python-2.7 ipython python-requests