发出HTTP DELETE请求时,请求URI应完全标识要删除的资源.但是,是否允许添加额外的元数据作为请求的实体主体的一部分?
我目前正在使用Google Cloud Run部署 API,尽管一切正常,但我现在很难理解我收到的错误。
\n我使用FastAPI在 python3 上创建了 API ,位置模型基于Pydantic\'s BaseModel。
\n为了说明这一点,我定义了一条测试路线,如下所示:
\nclass 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\'}\nRun Code Online (Sandbox Code Playgroud)\n该路由应在请求正文中采用两个参数:起点和目的地,并且只有当我在本地部署它时才会这样做。\n这:
\nurl_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)\nRun Code Online (Sandbox Code Playgroud)\n输出:
\n\'{"res":"ok"}\'\nRun 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