Python snippet for calling a REST service on the KNIME Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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