flask - 如何在烧瓶舞上发送带有 json 数据的发布请求?
问题描述
我正在尝试在我的烧瓶舞蹈扩展上向谷歌日历的忙闲服务发送 POST 请求。但我收到“405 Method Not Allowed”错误。我不知道如何调试它。
我必须在请求正文中传递 JSON 数据。我已经提到了请求文件。我是烧瓶和烧瓶舞的新手,任何帮助将不胜感激。
@app.route("/",methods=['POST'])
def free():
if not google.authorized:
return redirect(url_for("google.login"))
event = json.dumps({"timeMin": "2019-03-31T00:00:00Z",
"timeMax": "2019-04-01T00:00:00Z",
"timeZone": " Asia/Calcutta",
"groupExpansionMax": 3,
"calendarExpansionMax": 1,
"items": [
{
"id": "abcd@gmail.com"
}
]
})
resp = google.post(url="https://www.googleapis.com/calendar/v3/freeBusy",data=event)
return resp.json()
响应应该是 json 数据
"timeMax": "2019-04-01T00:00:00.000Z",
"kind": "calendar#freeBusy",
"calendars": {
"abcd@gmail.com": {
"busy": [
{
"start": "2019-03-31T03:00:00Z",
"end": "2019-03-31T09:00:00Z"
}
]
}
},
"timeMin": "2019-03-31T00:00:00.000Z"
}```
解决方案
添加 GET 和 POST,现在代码似乎可以工作
@app.route("/",methods=['GET','POST'])
def free():
if not google.authorized:
return redirect(url_for("google.login"))
event = {"timeMin": "2019-03-31T00:00:00Z",
"timeMax": "2019-04-01T00:00:00Z",
"timeZone": " Asia/Calcutta",
"groupExpansionMax": 3,
"calendarExpansionMax": 1,
"items": [
{
"id": "abcd@gmail.com"
}
]
}
推荐阅读
- css - 选择选项字体颜色未在移动设备上显示
- css - Vue动态改变背景位置
- javascript - Reactjs 选择值选项值映射迭代与默认值
- c# - 将 FNV-1a 算法从 C# 移植到 Lua,乘法结果不匹配
- python - 我需要创建一个使用 ZEEP 或 REQUEST 模块调用 SOAP GET 方法的 python 脚本
- javascript - 用查找或过滤方法替换两个 for 循环 - javascript
- sql - 使用group-by时如何将所有列聚合到SQL中的数组中?
- c# - 我对锯齿状数组感到困惑。我试图在访问、打印或更改元素时创建一个 for 循环。我怎样才能做到这一点?
- flutter - 无法使用颤振动画包创建动画
- python - ipywidgets Jupyter Notebook:选择多个复选框以过滤数据框并将其绘制出来