如何发送 post 请求和 json 烧瓶舞数据?

How can I send post request with json data on flask-dance?

我正在尝试向 google 日历的忙/闲 service 发送 POST 请求,使用我的 Flask 舞蹈扩展。但我收到“405 方法不允许”错误。不知道怎么调试。

我必须在请求正文中传递 JSON 数据。我已提交请求 documentation 。我是烧瓶和烧瓶舞的新手,如有任何帮助,我们将不胜感激。

@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"
}```

使用 POST 添加了 GET,现在代码似乎可以工作了


@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"
                 }
             ]
            }