相关疑难解决方法(0)

实体主体是否允许HTTP DELETE请求?

发出HTTP DELETE请求时,请求URI应完全标识要删除的资源.但是,是否允许添加额外的元数据作为请求的实体主体的一部分?

rest http

651
推荐指数
13
解决办法
36万
查看次数

Cloud Run 请求在未到达已部署服务的情况下触发错误 400

我目前正在使用Google Cloud Run部署 API,尽管一切正常,但我现在很难理解我收到的错误。

\n

我使用FastAPI在 python3 上创建了 API ,位置模型基于Pydantic\'s BaseModel。

\n

为了说明这一点,我定义了一条测试路线,如下所示:

\n
class Location(BaseModel):\n    lat: float\n    lng: float\n\n\n@router.get(\'/test_404\')\nasync def test_404(origin: Location = Body(...),\n                   destination: Location = Body(...)):\n    print(origin)\n    print(destination)\n    return {\'res\': \'ok\'}\n
Run Code Online (Sandbox Code Playgroud)\n

该路由应在请求正文中采用两个参数:起点和目的地,并且只有当我在本地部署它时才会这样做。\n这:

\n
url_local = "http://0.0.0.0:8080/test_404"\ndata = {\n    \'origin\': {\'lat\': 104, \'lng\': 342},\n    \'destination\': {\'lat\': 104, \'lng\': 342}\n}\nresp = requests.get(url_local, json = data)\nprint(resp.text)\n
Run Code Online (Sandbox Code Playgroud)\n

输出:

\n
\'{"res":"ok"}\'\n
Run Code Online (Sandbox Code Playgroud)\n

当我在 Cloud Run 上部署相同的服务时,就会出现问题。我的所有其他路线都工作正常,但以下是当我将上面的代码与容器 url 一起使用时得到的输出:

\n
    <!DOCTYPE html>\\n\n    <html lang=en>\n    <meta charset=utf-8>\n …
Run Code Online (Sandbox Code Playgroud)

python-3.x google-cloud-platform pydantic google-cloud-run fastapi

3
推荐指数
1
解决办法
3311
查看次数