小编Smi*_*ith的帖子

Python:带有 post 请求的 FastAPI 错误 422

我正在构建一个简单的 API 来测试数据库。当我使用 get request 时一切正常,但如果我更改为 post,我会收到“无法处理的实体”错误:

这是 FastAPI 代码:

from fastapi import FastAPI

app = FastAPI()

@app.post("/")
def main(user):
    return user
Run Code Online (Sandbox Code Playgroud)

然后,我的请求使用 javascript

let axios = require('axios')

data = { 
    user: 'smith' 
}

axios.post('http://localhost:8000', data)
    .then(response => (console.log(response.url)))
Run Code Online (Sandbox Code Playgroud)

并使用 Python

import requests

url = 'http://127.0.0.1:8000'
data = {'user': 'Smith'}

response = requests.post(url, json=data)
print(response.text)
Run Code Online (Sandbox Code Playgroud)

我也尝试解析为 json,使用 utf-8 编码,并更改标题。没有什么对我有用。

python python-requests axios fastapi

15
推荐指数
5
解决办法
3万
查看次数

<small> 可以位于 <p> 标签内吗?

我必须从 pdf 中制作一个语义网页。一切都很顺利(一点也不),但我有一个脚注不适合响应行高。我想把它放在 ap 标签内,效果很好,但我不知道这是否好。

这是代码:

.text {
  padding-left: 8.5vw;
  padding-right: 8.5vw;
  padding-bottom: 10vw;
}

.text-column {
  padding-top: 10vw;
  column-count: 2;
  column-gap: 4vw;
}

.text p {
  color: #333;
  margin-bottom: 2.7vw;
  line-height: 3vw;
  text-align: justify;
  text-indent: 3vw;
  font-size: 2.12vw;
}

.footnote hr {
  background-color: #000;
  width: 33%;
  height: 0.2vw;
  margin-top: 4vw;
  margin-bottom: 1vw;
  border-color: #000;
}

.footnote {
  font-size: 1.36vw !important;
  text-align: justify !important;
  line-height: 1em !important;
}

<article class="text text-column">
...

  <small class="footnote">
    <hr>
        Lorem ipsum dolor sit amet …
Run Code Online (Sandbox Code Playgroud)

html css

2
推荐指数
1
解决办法
1043
查看次数

标签 统计

axios ×1

css ×1

fastapi ×1

html ×1

python ×1

python-requests ×1