gpt4 book ai didi

python hug api返回自定义http代码

转载 作者:可可西里 更新时间:2023-11-01 16:06:25 25 4
gpt4 key购买 nike

找了好久,继续问: https://gitter.im/timothycrosley/hug我找不到解决方案。

我正在寻找的是一种返回自定义 http 代码的方法,比如说 204,以防在 get 端点满足条件。路由问题的解释是here

但我似乎无法找到一种方法来返回除 200 以外的任何其他代码和空响应

最佳答案

在他们的 repo ( https://github.com/berdario/hug/blob/5470661c6f171f1e9da609c3bf67ece21cf6d6eb/examples/return_400.py ) 中找到了一个例子

import hug
from falcon import HTTP_400

@hug.get()
def only_positive(positive: int, response):
if positive < 0:
response.status = HTTP_400

关于python hug api返回自定义http代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41444627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com