Skip to content

Instantly share code, notes, and snippets.

@greglandrum
Created September 29, 2017 09:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greglandrum/b76322c8224d8bef4091cc1c83fb9e45 to your computer and use it in GitHub Desktop.
Save greglandrum/b76322c8224d8bef4091cc1c83fb9e45 to your computer and use it in GitHub Desktop.
Python snippet for calling a REST service on the KNIME Server
# Define some generic functionality for accessing web services from the KNIME server
import requests,json
from requests import auth
def call_KNIME_WebService(serviceName,values,user,pw,baseURL="http://YOUR_SERVER_NAME_HERE:8080/webportal/rest/v4/repository/"):
url = "%s%s:job-pool"%(baseURL,serviceName)
authd = auth.HTTPBasicAuth(user,pw)
reqbody = json.dumps({"input-data":{"jsonvalue":qry}})
resp = requests.post(url,auth=authd,data=reqbody,headers={"Content-Type":"application/json"})
if resp.ok and resp.status_code==200:
outvs = resp.json()['outputValues']
return tuple(outvs.values())
raise RuntimeError(resp.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment