Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.