How can I consume a WSDL (SOAP) web service in Python?
I want to use a WSDL SOAP based web service in Python. I have looked at the Dive Into Python code but the SOAPpy module does not work under Python 2.5.
I have tried using suds which works partly, but breaks with certain types (suds.TypeNotFound: Type not found: 'item').
I have also looked at Client but this does not appear to support WSDL.
And I have looked at ZSI but it looks very complex. Does anyone have any sample code for it?
The WSDL is https://ws.pingdom.com/soap/PingdomAPI.wsdl and works fine with the PHP 5 SOAP client.
Asked by: Kirsten522 | Posted: 28-01-2022
Answer 1
I would recommend that you have a look at SUDS
"Suds is a lightweight SOAP python client for consuming Web Services."
Answered by: Kellan379 | Posted: 01-03-2022Answer 2
There is a relatively new library which is very promising and albeit still poorly documented, seems very clean and pythonic: python zeep.
See also this answer for an example.
Answered by: Ned603 | Posted: 01-03-2022Answer 3
I recently stumbled up on the same problem. Here is the synopsis of my solution:
Basic constituent code blocks needed
The following are the required basic code blocks of your client application
- Session request section: request a session with the provider
- Session authentication section: provide credentials to the provider
- Client section: create the Client
- Security Header section: add the WS-Security Header to the Client
- Consumption section: consume available operations (or methods) as needed
What modules do you need?
Many suggested to use Python modules such as urllib2 ; however, none of the modules work-at least for this particular project.
So, here is the list of the modules you need to get. First of all, you need to download and install the latest version of suds from the following link:
pypi.python.org/pypi/suds-jurko/0.4.1.jurko.2
Additionally, you need to download and install requests and suds_requests modules from the following links respectively ( disclaimer: I am new to post in here, so I can't post more than one link for now).
pypi.python.org/pypi/requests
pypi.python.org/pypi/suds_requests/0.1
Once you successfully download and install these modules, you are good to go.
The code
Following the steps outlined earlier, the code looks like the following: Imports:
import logging
from suds.client import Client
from suds.wsse import *
from datetime import timedelta,date,datetime,tzinfo
import requests
from requests.auth import HTTPBasicAuth
import suds_requests
Session request and authentication:
username=input('Username:')
password=input('password:')
session = requests.session()
session.auth=(username, password)
Create the Client:
client = Client(WSDL_URL, faults=False, cachingpolicy=1, location=WSDL_URL, transport=suds_requests.RequestsTransport(session))
Add WS-Security Header:
...
addSecurityHeader(client,username,password)
....
def addSecurityHeader(client,username,password):
security=Security()
userNameToken=UsernameToken(username,password)
timeStampToken=Timestamp(validity=600)
security.tokens.append(userNameToken)
security.tokens.append(timeStampToken)
client.set_options(wsse=security)
Please note that this method creates the security header depicted in Fig.1. So, your implementation may vary depending on the correct security header format provided by the owner of the service you are consuming.
Consume the relevant method (or operation) :
result=client.service.methodName(Inputs)
Logging:
One of the best practices in such implementations as this one is logging to see how the communication is executed. In case there is some issue, it makes debugging easy. The following code does basic logging. However, you can log many aspects of the communication in addition to the ones depicted in the code.
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
Result:
Here is the result in my case. Note that the server returned HTTP 200. This is the standard success code for HTTP request-response.
(200, (collectionNodeLmp){
timestamp = 2014-12-03 00:00:00-05:00
nodeLmp[] =
(nodeLmp){
pnodeId = 35010357
name = "YADKIN"
mccValue = -0.19
mlcValue = -0.13
price = 36.46
type = "500 KV"
timestamp = 2014-12-03 01:00:00-05:00
errorCodeId = 0
},
(nodeLmp){
pnodeId = 33138769
name = "ZION 1"
mccValue = -0.18
mlcValue = -1.86
price = 34.75
type = "Aggregate"
timestamp = 2014-12-03 01:00:00-05:00
errorCodeId = 0
},
})
Answered by: Connie656 | Posted: 01-03-2022
Answer 4
Zeep is a decent SOAP library for Python that matches what you're asking for: http://docs.python-zeep.org
Answered by: Ned288 | Posted: 01-03-2022Answer 5
Right now (as of 2008), all the SOAP libraries available for Python suck. I recommend avoiding SOAP if possible. The last time we where forced to use a SOAP web service from Python, we wrote a wrapper in C# that handled the SOAP on one side and spoke COM out the other.
Answered by: Arthur172 | Posted: 01-03-2022Answer 6
I periodically search for a satisfactory answer to this, but no luck so far. I use soapUI + requests + manual labour.
I gave up and used Java the last time I needed to do this, and simply gave up a few times the last time I wanted to do this, but it wasn't essential.
Having successfully used the requests library last year with Project Place's RESTful API, it occurred to me that maybe I could just hand-roll the SOAP requests I want to send in a similar way.
Turns out that's not too difficult, but it is time consuming and prone to error, especially if fields are inconsistently named (the one I'm currently working on today has 'jobId', JobId' and 'JobID'. I use soapUI to load the WSDL to make it easier to extract endpoints etc and perform some manual testing. So far I've been lucky not to have been affected by changes to any WSDL that I'm using.
Answered by: Briony199 | Posted: 01-03-2022Answer 7
It's not true SOAPpy does not work with Python 2.5 - it works, although it's very simple and really, really basic. If you want to talk to any more complicated webservice, ZSI is your only friend.
The really useful demo I found is at http://www.ebi.ac.uk/Tools/webservices/tutorials/python - this really helped me to understand how ZSI works.
Answered by: Lucas653 | Posted: 01-03-2022Answer 8
If you're rolling your own I'd highly recommend looking at http://effbot.org/zone/element-soap.htm.
Answered by: Grace476 | Posted: 01-03-2022Answer 9
SOAPpy is now obsolete, AFAIK, replaced by ZSL. It's a moot point, because I can't get either one to work, much less compile, on either Python 2.5 or Python 2.6
Answered by: Emma799 | Posted: 01-03-2022Answer 10
#!/usr/bin/python
# -*- coding: utf-8 -*-
# consume_wsdl_soap_ws_pss.py
import logging.config
from pysimplesoap.client import SoapClient
logging.config.dictConfig({
'version': 1,
'formatters': {
'verbose': {
'format': '%(name)s: %(message)s'
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'pysimplesoap.helpers': {
'level': 'DEBUG',
'propagate': True,
'handlers': ['console'],
},
}
})
WSDL_URL = 'http://www.webservicex.net/stockquote.asmx?WSDL'
client = SoapClient(wsdl=WSDL_URL, ns="web", trace=True)
client['AuthHeaderElement'] = {'username': 'someone', 'password': 'nottelling'}
#Discover operations
list_of_services = [service for service in client.services]
print(list_of_services)
#Discover params
method = client.services['StockQuote']
response = client.GetQuote(symbol='GOOG')
print('GetQuote: {}'.format(response['GetQuoteResult']))
Answered by: Kristian743 | Posted: 01-03-2022
Similar questions
python - how can I consume django web service in C#?
python - django webmethod returns simplejson.dumps,
how can I convert the simplejson string into C# 2.0 Object ?
for example,
dict -> Hashtable
string -> String
...
is there any JSON Serializable library in existing .NET framework or any 3rd party tool ?
Consume a python RPC service in JAVA
Can I be able to consume Python RPC service in Java?
Now I have a working prototype.. I wanted to get a list of all the available services in the server..
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://192.168.1.15:8010"));
client.setConfig(config);
Object[] params = new Object[0];
Object result = client.ex...
Consume Wsgi Python web service with php
Is there any tutorial on how can i Consume Wsgi Python web service with php ?
There is a few article on here like this:
"Call Python web service using PHP"
but im not using soap
here is my sample python web service :
import pymysql
import json
from bottle import route, run ,request
@route('/testing...
How do I make a Python client that can consume a .NET (soap) web service?
I'm trying to make a Python client that can consume a .NET (soap) web service. I've been looking at the suds library to do so, as it appears to be frequently recommended. This is what I have so far:
from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
ntlm_transport = WindowsHttpAuthenticated(username='myUserNa...
python - Consume web service with DJANGO
I have a django application to show some data from my database (ORACLE), but now I need to show some data from a web service.
I need to build a form based in the request of the web service, and show the response of the web service.
I googling to expose my app as a web service and send and retrieve XML data.
But I am very confused and I don't know where to start or which django package to use(PyXML,D...
python - Bypass SSL when I'm using SUDS for consume web service
I'm using SUDS for consuming web service. I tried like bellow:
client = Client(wsdl_url)
list_of_methods = [method for method in client.wsdl.services[0].ports[0].methods]
print(list_of_methods)
I got this error:
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)>
I saw
Unable to consume a .NET WCF service in Python
I am trying to access a .NET WCF web service from Python and am getting the following error - would anyone be able to let me know what I am doing wrong:
File "C:\temp\anaconda3\lib\site-packages\suds\mx\literal.py", line 87, in start
raise TypeNotFound(content.tag)
suds.TypeNotFound: Type not found: 'authToken'
Below is the python code that I have:
imp...
unable to consume SOAP service in zeep, python
I was trying to consume a soap service in python with zeep. I've consumed several soap services with zeep as well. But for a particular soap service, a weird response in returning, unlike a well-organized dictionary.
My python code is below:
import zeep
import json
def getToken1():
wsdl2 = 'http://trx.*********ast.co.id/Webservice/b******ervice?wsdl'
client2 = zeep.Client(wsdl2)
parameters = {
...
python - how can I consume django web service in C#?
python - django webmethod returns simplejson.dumps,
how can I convert the simplejson string into C# 2.0 Object ?
for example,
dict -> Hashtable
string -> String
...
is there any JSON Serializable library in existing .NET framework or any 3rd party tool ?
python - Django - consume XML - RESTful
I have a python script running fine on my localhost. Its not an enterprise app or anything, just something I'm playing around with. It uses the "bottle" library. The app basically consumes an XML file (stored either locally or online) which contains elements with their own unique IDs, as well as some coordinates, eg mysite.com/23 will bring back the lat/long of element 23. I'm sure you're all familiar with REST at this sta...
python - How to consume a File / Cursor line by line from another object that has no access to them
I have a program that reads objects (Tasks) from either a CSV file or a DB. Both source have in common that you must explicitely close access to the resource after using it.
I followed the approach of making both the CSV and the DB class iterable, so iterating over them returns tasks.
This is handy for using them, however I'm not convinced it's clean, and I have the following questions :
What is the b...
Consume a python RPC service in JAVA
Can I be able to consume Python RPC service in Java?
Now I have a working prototype.. I wanted to get a list of all the available services in the server..
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://192.168.1.15:8010"));
client.setConfig(config);
Object[] params = new Object[0];
Object result = client.ex...
python - Using Django to consume an API
Can someone point me in the right direction maybe example code?
I have written an API in TastyPie and I now also want to consume this API within my own Django app. (I want to eat my own Dog food and all that)
i.e. I currently list contacts (pure Django) I now want to asynchronous update a record on the page.
before I make a start writing a jquery sc...
Consume Wsgi Python web service with php
Is there any tutorial on how can i Consume Wsgi Python web service with php ?
There is a few article on here like this:
"Call Python web service using PHP"
but im not using soap
here is my sample python web service :
import pymysql
import json
from bottle import route, run ,request
@route('/testing...
Kafka and python - I dont get how to consume
From the docs..[1]: https://github.com/mumrah/kafka-python
# To send messages asynchronously
producer = SimpleProducer(kafka, async=True)
producer.send_messages("my-topic", "async message")
# To consume messages
consumer = SimpleConsumer(kafka, "my-group", "my-topic")
for message in consumer:
print(message)
Where did ...
Consume REST API from Python: do I need an async library?
I have a REST API and now I want to create a web site that will use this API as only and primary datasource. The system is distributed: REST API is on one group of machines and the site will be on the other(s).
I'm expecting to have quite a lot of load, so I'd like to make requests as efficient, as possible.
Do I need some async HTTP requests library or any HTTP client library will work?
API is done...
How do I make a Python client that can consume a .NET (soap) web service?
I'm trying to make a Python client that can consume a .NET (soap) web service. I've been looking at the suds library to do so, as it appears to be frequently recommended. This is what I have so far:
from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
ntlm_transport = WindowsHttpAuthenticated(username='myUserNa...
python - Consume queue from other thread
I am developing an script in which I want to have 2 threads. One of them will keep reading serial port and the other one will listen to zmq.
I want to use a queue for the first thread know when to stop reading serial port. so I want the second thread, fill a queue with a character each time it receives a message from zmq.
I already have this:
import serial
import struct
import threading
...
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python