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

240
Views
trying to send a POST request using python with a JSON object and print the response into a CSV file

I am trying to send a post request using python script and want to store the response. Below are the two file. Everything is fine when i do the same thing using node.js but when I use a python script instead of node.js it give me this error. Any one know why? not able to find the proper reason why this error pop up.

in request sending first name and last name and in response i will get the full name

Node.js Code (used fastify)

const conn=require('fastify')({
    logger:true
})
const PORT=80
const axios = require('axios')

//take first and last name as request and in response return full name
conn.post('/user',async(req,res)=>{
    const user=req.body
    const fullname=user.first_name + user.last_name
    console.log(full)
    res.json(fullname)
})


const start_server=async()=>{
    try
    {
        await conn.listen(PORT)
        console.log(`server start at PORT ${PORT}`)
    }
    catch(error)
    {
        conn.log.error(error)
        process.exit(1)
    }
}
start_server()

my Python script

import requests
import json
API_ENDPOINT = 'http://localhost:80/user'

headers = {'Content-type': 'application/json'}

data = {
  "first_name": "jayanta",
  "last_name": "lahkar"
}

r = requests.post('http://localhost:80/user', data)

print(r.json())

Error message

{'statusCode': 415, 'code': 'FST_ERR_CTP_INVALID_MEDIA_TYPE', 'error': 'Unsupported Media Type', 'message': 'Unsupported Media Type: application/x-www-form-urlencoded'}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Try:

r = requests.post(url = 'http://localhost:80/user', headers=headers, data=data)

print(r.json())
about 4 years ago · Juan Pablo Isaza Report

0

in the python script:

use json

r = requests.post(url = 'http://localhost:80/user', headers=headers, json=data)

in the node script:

use .send method

const {first_name, last_name} =req.body;
const fullname={first_name, last_name};
res.send(fullname);
about 4 years ago · Juan Pablo Isaza Report

0

here is the answer to your error:

axios.post('url', data, {
        headers: {
            'Content-Type': 'application/json',
        }
    }
about 4 years ago · Juan Pablo Isaza 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!