Python SOAP request using urllib2

时光怂恿深爱的人放手 提交于 2019-12-06 11:07:47

See the code below if it gives you some clues. I am simply calling a SOAP service using only urllib2 with Python 2.6.6. This worked fine for me. Be careful because I've added some code to pass through a proxy that you may or not need. In my particular case I am invoking a SOAP service in an Oracle Data Integrator (ODI)

import urllib2

url = "http://alexmoleiro.com:20910/oraclediagent/OdiInvoke?wsdl"

post_data = """<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <OdiStartScenRequest xmlns="xmlns.oracle.com/odi/OdiInvoke/">
            <Credentials xmlns="">
                 <OdiUser>loquesea</OdiUser>
                <OdiPassword>aversiacierto</OdiPassword>
               <WorkRepository>repofacil</WorkRepository>
         </Credentials>            
        </OdiStartScenRequest>
    </Body>
</Envelope>
"""

http_headers = {
    "Accept": "application/soap+xml,multipart/related,text/*",
    "Cache-Control": "no-cache",
    "Pragma": "no-cache",
    "Content-Type": "text/xml; charset=utf-8"

}

request_object = urllib2.Request(url, post_data, http_headers)

#IF YOU ARE NOT BEHIND A PROXY, DELETE THIS BLOCK
http_proxy_server = "10.115.4.2"
http_proxy_port = "8080"
http_proxy_realm = http_proxy_server
http_proxy_full_auth_string = "http://%s:%s" % (http_proxy_server, http_proxy_port)
proxy = urllib2.ProxyHandler({'http': http_proxy_full_auth_string})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
#END OF --> IF YOU ARE NOT BEHIND A PROXY, DELETE THIS BLOCK


response = urllib2.urlopen(request_object)
html_string = response.read()
print html_string

Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!