我想知道从Python应用程序调用OpenWhisk操作的最简单方法是什么? 也许等同于https://github.com/apache/incubator-openwhisk-client-js/但在Python中。我知道曾经有一个基于Python的CLI(https://github.com/apache/incubator-openwhisk-client-python),但我没有找到任何关于如何从我的Python脚本中重用它的文档。
答案 0 :(得分:1)
从Python应用程序调用操作将需要您向平台API发送HTTP请求。没有适用于Python的官方OpenWhisk SDK。
示例代码显示了如何使用requests
库调用平台API。
import subprocess
import requests
APIHOST = 'https://openwhisk.ng.bluemix.net'
AUTH_KEY = subprocess.check_output("wsk property get --auth", shell=True).split()[2]
NAMESPACE = 'whisk.system'
ACTION = 'utils/echo'
PARAMS = {'myKey':'myValue'};
BLOCKING = 'true'
RESULT = 'true'
url = APIHOST + '/api/v1/namespaces/' + NAMESPACE + '/actions/' + ACTION
user_pass = AUTH_KEY.split(':')
response = requests.post(url, json=PARAMS, params={'blocking': BLOCKING, 'result': RESULT}, auth=(user_pass[0], user_pass[1]))
print(response.text)
可以使用完整API的Swagger文档here。
有一个open issue来创建一个Python客户端库,以使这更容易。