<响应 [400]>将带有 json 正文的 api get 请求发送到部署在 google app engine 上的 api 时

发布于 2025-01-20 18:45:38 字数 1012 浏览 4 评论 0原文

我正在做一项学校作业,我创建了一个简单的 api 来读取数据并将数据添加到 firebase 数据库。我们在本地尝试过,效果很好。现在,我正在尝试将其部署到谷歌应用程序引擎,但遇到了一个非常烦人的问题。如果我在函数内部设置参数(现在已注释掉),我会得到有效的响应。但是,如果我尝试输入 json 正文并使用 RequestParser 解析它,我会收到。有谁知道为什么这可以在本地工作,但一旦部署到谷歌应用程序引擎就不行了?如果有任何不清楚的地方,我很乐意澄清!

def get(self):
    parser = reqparse.RequestParser()
    parser.add_argument("name",type=str,help = "name of recipe or ingredient is required",required = True)
    args = parser.parse_args()
    #args = dict({"name":"Carbonara"})

    if(args["name"] == 'all'):
        hej = getCollection()
        return {'data': hej},200

    recipes = getRecipes(args["name"])
    if(recipes != None):
        return recipes,200
    result = recipeContains(args["name"])
    if result != []:
        return result,200
    return "No results"

response = requests.get("https://cohesive-photon-346611.ew.r.appspot.com/recipes", {"name":"Carbonara"})

response = requests.get("https://cohesive-photon-346611.ew.r.appspot.com/recipes")

I'm working on a school assignment where I've created a simple api to read and add data to a firebase database. We've tried it locally and it works fine. Now, I'm trying to deploy it to google app engine and I've encountered a very annoying issue. If I set the argument inside of the function (as is now commented out), I get a valid response. But if I try to enter a json body and parse it with RequestParser, I get a <Response 400>. Does anyone know why this works locally but not once it's deployed to google app engine? If anything is unclear, I'll be happy to clarify!

def get(self):
    parser = reqparse.RequestParser()
    parser.add_argument("name",type=str,help = "name of recipe or ingredient is required",required = True)
    args = parser.parse_args()
    #args = dict({"name":"Carbonara"})

    if(args["name"] == 'all'):
        hej = getCollection()
        return {'data': hej},200

    recipes = getRecipes(args["name"])
    if(recipes != None):
        return recipes,200
    result = recipeContains(args["name"])
    if result != []:
        return result,200
    return "No results"

response = requests.get("https://cohesive-photon-346611.ew.r.appspot.com/recipes", {"name":"Carbonara"})

response = requests.get("https://cohesive-photon-346611.ew.r.appspot.com/recipes")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文