run request with owslib


In [1]:
from owslib.wps import WebProcessingService, monitorExecution, printInputOutput

In [2]:
wps = WebProcessingService(url="http://birdhouse-lsce.extra.cea.fr:8094/wps", verbose=False)

In [3]:
for process in wps.processes:
    print '%s : \t %s' % (process.identifier, process.abstract, )


helloworld : 	 Welcome user and say hello ...
ultimatequestionprocess : 	 Numerical solution that is the answer to Life, Universe and Everything. The process is an improvement to Deep Tought computer (therefore version 2.0) since it no longer takes 7.5 milion years, but only a few seconds to give a response, with an update of status every 10 seconds.
dummyprocess : 	 The Dummy process is used for testing the WPS structure. The process will accept 2 input numbers and will return the XML result with an add one and subtract one operation
wordcount : 	 Counts words in a given text ...
inout : 	 Just testing data types like date, datetime etc ...
multiplesources : 	 Process with multiple different sources ...
chomsky : 	 Generates a random chomsky text ...
zonal_mean : 	 zonal mean in NetCDF File.

In [ ]:
p = wps.describeprocess(identifier='ultimatequestionprocess')
for input in p.dataInputs:
    printInputOutput(input)

In [6]:
execute = wps.execute(
    identifier="ultimatequestionprocess", 
    inputs=[])

monitorExecution(execute, sleepSecs=5)

print execute.getStatus()

for o in execute.processOutputs:
    print o.reference


  File "<string>", line unknown
XMLSyntaxError: Opening and ending tag mismatch: hr line 5 and body, line 6, column 8

run sync request with get parameters


In [7]:
sync_req_url = "http://birdhouse-lsce.extra.cea.fr:8094/wps?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=ultimatequestionprocess" +\
    "&DataInputs=" +\
    "&storeExecuteResponse=false" +\
    "&status=false"

In [8]:
url=sync_req_url.format()
print url


http://birdhouse-lsce.extra.cea.fr:8094/wps?request=Execute&service=WPS&version=1.0.0&identifier=ultimatequestionprocess&DataInputs=&storeExecuteResponse=false&status=false

In [9]:
import requests
r = requests.get(url)
print r.status_code
print r.text


502
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>

run async request with get parameters


In [18]:
async_req_url = "http://birdhouse-lsce.extra.cea.fr:8094/wps?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=ultimatequestionprocess" +\
    "&DataInputs=" +\
    "&storeExecuteResponse=true" +\
    "&status=true"

In [19]:
url=async_req_url.format()
print url


http://birdhouse-lsce.extra.cea.fr:8094/wps?request=Execute&service=WPS&version=1.0.0&identifier=ultimatequestionprocess&DataInputs=&storeExecuteResponse=true&status=true

In [20]:
r = requests.get(url)
from lxml import etree
from io import BytesIO
tree = etree.parse(BytesIO(r.content))
#print etree.tostring(tree)
status_url = tree.getroot().get("statusLocation")
print status_url


http://birdhouse-lsce.extra.cea.fr:8090/wpsoutputs/emu/pywps-7e9ce004-beaa-11e5-ac13-79c338e72e5f.xml

In [33]:
r = requests.get(status_url)
print r.status_code
print r.text


200
<?xml version="1.0" encoding="utf-8"?>
<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="en-CA" serviceInstance="http://birdhouse-lsce.extra.cea.fr:8094/wps?service=WPS&amp;request=GetCapabilities&amp;version=1.0.0" statusLocation="http://birdhouse-lsce.extra.cea.fr:8090/wpsoutputs/emu/pywps-7e9ce004-beaa-11e5-ac13-79c338e72e5f.xml">
    <wps:Process wps:processVersion="2.0">
        <ows:Identifier>ultimatequestionprocess</ows:Identifier>
        <ows:Title>Answer to Life, the Universe and Everything</ows:Title>
        <ows:Abstract>Numerical solution that is the answer to Life, Universe and Everything. The process is an improvement to Deep Tought computer (therefore version 2.0) since it no longer takes 7.5 milion years, but only a few seconds to give a response, with an update of status every 10 seconds.</ows:Abstract>
    </wps:Process>
    <wps:Status creationTime="2016-01-19T13:51:58Z">
        <wps:ProcessSucceeded>PyWPS Process ultimatequestionprocess successfully calculated</wps:ProcessSucceeded>
    </wps:Status>
    <wps:ProcessOutputs>
        <wps:Output>
            <ows:Identifier>answer</ows:Identifier>
            <ows:Title>The numerical answer to Life, Universe and Everything</ows:Title>
            <wps:Data>
                <wps:LiteralData dataType="integer">42</wps:LiteralData>
            </wps:Data>
        </wps:Output>
    </wps:ProcessOutputs>
</wps:ExecuteResponse>

In [ ]:


In [ ]: