我想知道从 Python 应用程序调用 OpenWhisk 操作的最简单方法是什么?也许相当于https://github.com/apache/incubator-openwhisk-client-js/但在 Python 中。我知道曾经有一个基于 Python 的 CLI ( https://github.com/apache/incubator-openwhisk-client-python ),但我还没有找到任何关于如何从我的 Python 脚本中重用它的文档。
问问题
474 次
1 回答
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 文档可在此处获得。
有一个未解决的问题是创建一个 Python 客户端库以使这更容易。
于 2017-06-19T09:48:14.047 回答