run request with owslib


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

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

In [5]:
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 [6]:
p = wps.describeprocess(identifier='ultimatequestionprocess')
for input in p.dataInputs:
    printInputOutput(input)

In [5]:
in_file1 = 'file:///home/estimr1/EUCLEIA/gws-access.ceda.ac.uk/public/mohc_shared/EUCLEIA/MOHC/HadGEM3-A-N216/historical/r1i1p1/tas_day_HadGEM3-A-N216_historical_r1i1p1_19600101-19691230.nc'
#in_file1 = 'file:///homel/nhempel/data/NCEP/slp.1948-2014_NA.nc'
#in_file1 = 'file:///home/pingu/Public/data/esgf-archive/CORDEX/cordex/output/WAS-44/MPI-CSC/MPI-M-MPI-ESM-LR/historical/r1i1p1/MPI-CSC-REMO2009/v1/day/tasmax/v20140918/tasmax_WAS-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_MPI-CSC-REMO2009_v1_day_20010101-20051231.nc'

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


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

In [ ]:
monitorExecution(execute, sleepSecs=1)

print execute.getStatus()

for o in execute.processOutputs:
    print o.reference

run sync request with get parameters


In [9]:
sync_req_url = "http://localhost:8094/wps?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=ultimatequestionprocess" +\
    "&DataInputs=" +\
    "&storeExecuteResponse=false" +\
    "&status=false"

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


http://localhost:8094/wps?request=Execute&service=WPS&version=1.0.0&identifier=ultimatequestionprocess&DataInputs=&storeExecuteResponse=false&status=false

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


---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
<ipython-input-11-5da2f1a2832f> in <module>()
      1 import requests
----> 2 r = requests.get(url)
      3 print r.status_code
      4 print r.text

/homel/nhempel/.conda/envs/birdhouse/lib/python2.7/site-packages/requests/api.pyc in get(url, **kwargs)
     66 
     67     kwargs.setdefault('allow_redirects', True)
---> 68     return request('get', url, **kwargs)
     69 
     70 

/homel/nhempel/.conda/envs/birdhouse/lib/python2.7/site-packages/requests/api.pyc in request(method, url, **kwargs)
     48 
     49     session = sessions.Session()
---> 50     response = session.request(method=method, url=url, **kwargs)
     51     # By explicitly closing the session, we avoid leaving sockets open which
     52     # can trigger a ResourceWarning in some cases, and look like a memory leak

/homel/nhempel/.conda/envs/birdhouse/lib/python2.7/site-packages/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    462         }
    463         send_kwargs.update(settings)
--> 464         resp = self.send(prep, **send_kwargs)
    465 
    466         return resp

/homel/nhempel/.conda/envs/birdhouse/lib/python2.7/site-packages/requests/sessions.pyc in send(self, request, **kwargs)
    574 
    575         # Send the request
--> 576         r = adapter.send(request, **kwargs)
    577 
    578         # Total elapsed time of the request (approximately)

/homel/nhempel/.conda/envs/birdhouse/lib/python2.7/site-packages/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
    413 
    414         except (ProtocolError, socket.error) as err:
--> 415             raise ConnectionError(err, request=request)
    416 
    417         except MaxRetryError as e:

ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))

run async request with get parameters


In [ ]:
async_req_url = "http://localhost:8093/wps?" +\
    "request=Execute" +\
    "&service=WPS" +\
    "&version=1.0.0" +\
    "&identifier=subset_countries" +\
    "&DataInputs=resource={resource};region={region}" +\
    "&storeExecuteResponse=true" +\
    "&status=true"

In [ ]:
url=async_req_url.format(
    resource=in_file1,
    region='FRA')
print url

In [ ]:
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

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

In [ ]: