Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
How to post request JSON to fastapi, and retrieve whole JSON in the post function

I want to pass a JSON object to a fastapi backend. Here is what I am doing in the frontend app:

data = {'labels': labels, 'sequences': sequences}
response = requests.post(api_url, data = data)

Here is how the backend API looks like in fastapi:

@app.post("/api/zero-shot/")
async def Zero_Shot_Classification(request: Request):
    data = await request.json()

However, I am seeing an error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should use json parameter instead (which will change the Content-Type in the header to application/json), not data which is used for sending form data. Also, please have a look at the documentation on how to benefit from using Pydantic models for request bodies.

response = requests.post(api_url, json=data)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!