问题
I understand the very first reaction of someone who is reading this is to say "Ah this is a duplicate request" but believe me this is not. I have tried all the examples listed in stack-overflow to achieve what i wanted but still failed to do so.
I want to send the following details that I see in SoapUI to a given WSDL either via urllib2 or requests with following settings after failing miserably to get this done through Zeep and Suds
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:slab="http://m2.slab">
<soapenv:Header/>
<soapenv:Body>
<slab:PLChecker>
<!--Optional:-->
<slab:request>
<!--Optional:-->
<slab:ServiceProviderReferenceNumber>?</slab:ServiceProviderReferenceNumber>
<!--Optional:-->
<slab:ServiceNumber>0235625452</slab:ServiceNumber>
</slab:request>
</slab:PLChecker>
</soapenv:Body>
</soapenv:Envelope>
This is the SoapUI settings I've used
I have tried httpbasic authentication so far but seems like im lost at how to create a soap envelope with correct:
- Encording
- username
- password
- Authentication type : No authentication
- WSS Password type : PasswordText
Any help on this is much appreciated. This is the code i've been using so far.
import requests
from requests.auth import HTTPBasicAuth
import requests
import base64
import urllib
import ssl
ssl.match_hostname = lambda cert, hostname: True
import logging
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
url="https://commontest/PService.svc?singleWsdl"
# headers = {'content-type': 'application/soap+xml'}
request_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:slab="http://m2.com.au/slab">
<soapenv:Header/>
<soapenv:Body>
<slab:PLChecker>
<!--Optional:-->
<slab:request>
<!--Optional:-->
<slab:ServiceProviderReferenceNumber>?</slab:ServiceProviderReferenceNumber>
<!--Optional:-->
<slab:ServiceNumber>?</slab:ServiceNumber>
</slab:request>
</slab:PLChecker>
</soapenv:Body>
</soapenv:Envelope>"""
response = requests.post(url,data=body, verify = False, auth = ('user', 'pass'), headers = request_headers)
print response
来源:https://stackoverflow.com/questions/53624965/send-soap-1-1-request-through-python-requests-or-urllib