【发布时间】:2020-07-29 15:13:08
【问题描述】:
我是新手,正在尝试在 IBM Cloud 上创建 Cloud Function。 我的 API 仅在“hello world”上运行良好。我需要将参数从 URL 传递到我的 Python API 中。 喜欢:
网址:https://fa75e0fa.eu-gb.apigw.appdomain.cloud/testapi/test1?id=11
我需要将上述 URL 末尾的 id=11 的值传递到我的 Python 代码(Python 3.70)中。
我现在有这个:
#
#
# main() will be run when you invoke this action
#
# @param Cloud Functions actions accept a single parameter, which must be a JSON object.
#
# @return The output of this action, which must be a JSON object.
#
#
import sys
def main(dict):
return { 'message': 'Hello world' }
输出是: { “消息”:“你好世界” }
我试过了:
import sys
import urllib3, requests, json
import requests
import os
def main(dict):
id1=requests.GET.get('id')
return { 'message': 'Hello world',
'id': json.loads(id1.text)
}
输出是:
激活 ID: 4e97b3be9b2b49f397b3be9b2b99f34d 结果: { “错误”:“模块‘请求’没有属性‘获取’” } 日志:
[ "2020-04-16T11:29:34.215661Z stderr: Traceback (最近 最后调用):“,”2020-04-16T11:29:34.215717Z标准错误:文件 \"/action/1/src/exec__.py\",第 66 行,在 ",
"2020-04-16T11:29:34.215722Z stderr: res = main(payload)",
“2020-04-16T11:29:34.215725Z 标准错误:文件 \"/action/1/src/main__.py\",第 10 行,在 main",
“2020-04-16T11:29:34.215728Z 标准错误:id1=requests.GET.get('id')”,
“2020-04-16T11:29:34.215731Z 标准错误:属性错误:模块 'requests' 没有属性 'GET'", "2020-04-16T11:29:34.215734Z
标准错误:" ]
你能帮忙吗? 谢谢。
【问题讨论】:
标签: python api ibm-cloud ibm-cloud-functions