Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
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 Respuestas
Responde la pregunta

0

Try:

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

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

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 Denunciar

0

here is the answer to your error:

axios.post('url', data, {
        headers: {
            'Content-Type': 'application/json',
        }
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda