将POST请求发送到我的RESTful API(Python-Flask),但收到GET请求

乔尔·金斯利

我正在尝试以包含JSON的POST请求的形式将触发器发送到Zapier Webhook。如果我只是通过本地python脚本发送POST请求,则效果很好。

我想做的是创建一个RESTful API,当调用create-row-in-gs端点时,它会触发Zapier Webhook。

如您所见,我正在向Hasura集群发送POST请求API调用。但是,我没有得到“ 200 OK成功”的响应,而是得到了“ 200 OK成功”,这意味着该请求被视为GET请求而不是POST请求。

test.py

#Python 3 Script to send a POST request containing JSON

import json
import requests

api_url = 'http://app.catercorner16.hasura-app.io/create-row-in-gs'
create_row_data = {'id': '1235','name':'Joel','created-on':'27/01/2018','modified-on':'27/01/2018','desc':'This is Joel!!'}
r = requests.post(url=api_url, data=create_row_data)
print(r.status_code, r.reason, r.text)

server.py(在Hasura群集上运行)

from src import app
from flask import jsonify,request,make_response,url_for,redirect
from json import dumps
from requests import post

url = 'https://hooks.zapier.com/hooks/catch/xxxxx/yyyyy/'

@app.route('/create-row-in-gs', methods=['GET','POST'])
def create_row_in_gs():
    if request.method == 'GET':
        return make_response('failure')
    if request.method == 'POST':
        t_id = request.json['id']
        t_name = request.json['name']
        created_on = request.json['created_on']
        modified_on = request.json['modified_on']
        desc = request.json['desc']

        create_row_data = {'id': str(t_id),'name':str(t_name),'created-on':str(created_on),'modified-on':str(modified_on),'desc':str(desc)}

        response = requests.post(
            url, data=json.dumps(create_row_data),
            headers={'Content-Type': 'application/json'}
        )
        return response

已经为此努力了数周。我究竟做错了什么?将不胜感激。

mn

确保您使用的协议正确。httphttps

如果您使用http并看到重定向,则重定向Location标头通常将具有正确的URL。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何阻止请求被发送到我的 API

如何将请求标头发送到Restful API

我们如何使用curl将GET请求发送到外部API‽?

为什么我不能使用Python的`requests`库将“无”作为数据发送到POST请求中?

我想将文件作为附件发送到API POST请求

使用 Java 将 Cucumber.json 文件发送到 Jira 的 Rest API post 请求

Symfony2将POST请求发送到外部API并解析其XML响应?

将JSON POST请求发送到PHP中的REST API

如何读取/处理在POST请求中发送到Flask API的音频文件?

将请求发送到Java中的Google Elevation API

将POST请求发送到Google Action / API.AI或发送响应时间超过5s

使用python将HTTP请求行发送到jupyter

python请求如何将数据发送到网站

如何使用Python请求将图像发送到Strapi?

使用Flutter将http后请求(包含图像)发送到Flask API

使用后请求将压缩的numpy数组(zlib)发送到flask服务器[python]

如何将请求永久发送到我的http服务器

使用python中的AWS Lambda将发布请求发送到外部API

使用 Python 请求将数据和文件发送到 Forge API

如何将GET请求从Internet Explorer发送到Asp.Net Core API?

在Vue.js中使用axios将get请求发送到Laravel API

如何在PHP cURL请求中将OData发送到RESTful API

在Postman中进行测试(将文件发送到API)时,为什么我的简单发布请求不起作用?

如何(安全)将Python对象发送到Flask API?

“应用程序代理”将请求发送到我的“ shopify商店”,而不是我的应用程序?[Shopify]

如何将熊猫数据框发送到flask_restful API?

Python Flask 服务器收到“代码 400”错误(从 Telegram-webhook 发送的 POST 请求)

如何使用python通过POST请求将带有元数据(标题,描述)的媒体发送到WordPress REST API

将 POST 请求从 js 文件发送到 php 文件