<响应 [400]>将带有 json 正文的 api get 请求发送到部署在 google app engine 上的 api 时响应>
我正在做一项学校作业,我创建了一个简单的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论