1

I am working on developing an API for a web application using Quart and Quart-Schema. GET and PUT calls to the API work fine. The API is running in Kubernetes hosted on DigitalOcean. All the calls work fine on the docs page. POST calls are not working and The only error message I am getting is 400 BAD REQUEST Bad request or unsupported method. Any input would be invaluable.

Following PUT curl works:

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

The Below POST curl does not work:

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}"

This is the code responsible for the 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)

My dockerfile is below:

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"]

My 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
davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

0

The body of your request is malformed.

Update it so the numbers do not have leading zeros (or are strings):

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

Reference

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.
   ...
im_baby
  • 912
  • 1
  • 8
  • 14