1

我正在使用 Quart 和 Quart-Schema 为 Web 应用程序开发 API。对 API 的 GET 和 PUT 调用工作正常。该 API 在 DigitalOcean 上托管的 Kubernetes 中运行。所有调用都在文档页面上正常工作。POST 调用不起作用,我收到的唯一错误消息是400 BAD REQUEST Bad request or unsupported method. 任何输入都是无价的。

以下 PUT curl 工作:

curl -X PUT "https://app.restake.net/api/helper/email" -H  "accept: application/json" -H    "Content-Type: application/json" -d "{\"check\":\"jmsdevln@gmail.com\"}"

下面的 POST 卷曲不起作用:

curl -X POST "https://app.restake.net/api/user" -H  "accept: application/json" -H  "Content-                        Type: application/json" -d "{  \"discord_id\": 02,  \"email\": \"string2\",  \"password\": \"string\",  \"telegram_id\": 02}"

这是负责 POST 的代码:

@app.route("/api/user", methods=['POST'])
@validate_request(User_)
@validate_response(User, 201)
async def createNewUser(data: User_) -> User:
"""Create a New User

This creates a new user in the PostgreSQL database.
"""
result = await psql.createUser(app.pool, asdict(data))
if result is not None:
    return User(**result), 201
else:
    abort(404)

我的dockerfile如下:

FROM python:3.9.1-slim-buster
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install system dependencies
RUN apt-get update && apt-get install -y build-essential
RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt
COPY ./project/ /usr/src/app/project/
COPY ./manage.py /usr/src/app/
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh
EXPOSE 5000
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

我的 Kubernetes YAML:

---
apiVersion: v1
kind: Service
metadata:
  name: dashb-quart
  namespace: restakenet
spec:
  ports:
  - port: 5000
    targetPort: 5000
  selector:
    app: restake
    tier: dashboard
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: restake-quart-dashboard-dev
  namespace: restakenet
spec:
  replicas: 3
  selector:
    matchLabels:
      app: restake
      tier: dashboard
  template:
    metadata:
      labels:
        app: restake
        tier: dashboard
    spec:
      containers:
      - name: restake-quart-dashboard-dev
        image: boyroywax/restake-quart-dashboard-dev:latest
        imagePullPolicy: Always
        args: ["hypercorn", "--bind", "0.0.0.0:5000", "manage:app"]
        ports:
        - containerPort: 5000
          name: dashb-qaurt
4

1 回答 1

0

您的请求正文格式不正确。

更新它,使数字没有前导零(或者是字符串):

{
    "discord_id": 2,
    "email": "string2",
    "password": "string",
    "telegram_id": 2
}

参考

RFC 4627

2.4.  Numbers

   The representation of numbers is similar to that used in most
   programming languages.  A number contains an integer component that
   may be prefixed with an optional minus sign, which may be followed by
   a fraction part and/or an exponent part.

   Octal and hex forms are not allowed.  Leading zeros are not allowed.
   ...
于 2021-02-12T04:30:50.880 回答