我想知道从 Python 应用程序调用 OpenWhisk 操作的最简单方法是什么? 也许相当于 https://github.com/apache/incubator-openwhisk-client-js/但是在 Python 中。我知道曾经有一个基于 Python 的 CLI ( https://github.com/apache/incubator-openwhisk-client-python ),但我没有找到任何关于如何从我的 Python 脚本中重用它的文档。
请您参考如下方法:
从 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 客户端库来简化此过程。
