Home > database >  Problems on post method with form and tuple data
Problems on post method with form and tuple data

Time:10-20

I'm trying to make a post request to this url:

url

I'm trying this code to get this request:

from requests import get, post

data = {
    'entrada': {
        'site': 'site',
        'origen': 'origen',
        'tipo': 'turismo',
        'fecha': 2022,
        'marca': -1,
        'marcanombre': '',
        'modelo': -1,
        'modelonombre': '',
        'carroceria': -1,
        'carrocerianombre': '',
        'cambio': -1,
        'combustible': -1,
        'precio_desde': -1,
        'precio_hasta': -1,
        'potencia_desde': -1,
        'potencia_hasta': -1,
        'mercado': 'es'
    },
    'salida': ['marca', 'carroceria'],
}

headers = {"Content-Type": "application/x-www-form-urlencoded"}

post('https://configurador.mywebsite.com/service.php?servicio=getBuscador&canal=canal', headers=headers, data=data['entrada']).text

I should receive a response like:

{"marca":[{"ID":"Abarth","NOMBRE":"Abarth","FOTO":"\/logos_marcas_50x50\/logo_ABARTH.png"},
{"ID":"Aiways","NOMBRE":"Aiways","FOTO":"\/logos_marcas_50x50\/logo_AIWAYS.png"},
{"ID":"Alfa Romeo","NOMBRE":"Alfa Romeo","FOTO":"\/logos_marcas_50x50\/logo_ALFA ROMEO.png"},
{"ID":"Alpine","NOMBRE":"Alpine","FOTO":"\/logos_marcas_50x50\/logo_ALPINE.png"},
{"ID":"Audi","NOMBRE":"Audi","FOTO":"\/logos_marcas_50x50\/logo_AUDI.png"},
{"ID":"Bentley","NOMBRE":"Bentley","FOTO":"\/logos_marcas_50x50\/logo_BENTLEY.png"},
{"ID":"BMW","NOMBRE":"BMW","FOTO":"\/logos_marcas_50x50\/logo_BMW.png"},
{"ID":"Citro\u00ebn","NOMBRE":"Citro\u00ebn","FOTO":"\/logos_marcas_50x50\/logo_CITRO\u00cbN.png"},
{"ID":"CUPRA","NOMBRE":"CUPRA","FOTO":"\/logos_marcas_50x50\/logo_CUPRA.png"},
{"ID":"Dacia","NOMBRE":"Dacia","FOTO":"\/logos_marcas_50x50\/logo_DACIA.png"},
{"ID":"DFSK","NOMBRE":"DFSK","FOTO":"\/logos_marcas_50x50\/logo_DFSK.png"}]}

But I'm getting an empty list. Any ideas how to make this post request?

CodePudding user response:

Try:

import requests

api_url = "https://configurador.motorflash.com/tm_servicios.php?servicio=getBuscador&canal=jato"

payload = {
    "entrada[site]": "motorflashback",
    "entrada[origen]": "jato",
    "entrada[tipo]": "turismo",
    "entrada[fecha]": "2020",
    "entrada[marca]": "-1",
    "entrada[marcanombre]": "",
    "entrada[modelo]": "-1",
    "entrada[modelonombre]": "",
    "entrada[carroceria]": "-1",
    "entrada[carrocerianombre]": "",
    "entrada[cambio]": "-1",
    "entrada[combustible]": "-1",
    "entrada[precio_desde]": "-1",
    "entrada[precio_hasta]": "-1",
    "entrada[potencia_desde]": "-1",
    "entrada[potencia_hasta]": "-1",
    "entrada[mercado]": "es",
    "salida[]": ["marca", "carroceria"],
}

data = requests.post(api_url, data=payload).json()
print(data)

Prints:

{
    "marca": [
        {
            "ID": "Abarth",
            "NOMBRE": "Abarth",
            "FOTO": "/logos_marcas_50x50/logo_ABARTH.png",
        },
        {
            "ID": "Alfa Romeo",
            "NOMBRE": "Alfa Romeo",
            "FOTO": "/logos_marcas_50x50/logo_ALFA ROMEO.png",
        },
        {
            "ID": "Alpine",
            "NOMBRE": "Alpine",
            "FOTO": "/logos_marcas_50x50/logo_ALPINE.png",
        },
        {
            "ID": "Aston Martin",
            "NOMBRE": "Aston Martin",
            "FOTO": "/logos_marcas_50x50/logo_ASTON MARTIN.png",
        },
        {
            "ID": "Audi",
            "NOMBRE": "Audi",
            "FOTO": "/logos_marcas_50x50/logo_AUDI.png",
        },
        {
            "ID": "Bentley",
            "NOMBRE": "Bentley",
            "FOTO": "/logos_marcas_50x50/logo_BENTLEY.png",
        },
        {
            "ID": "BMW",
            "NOMBRE": "BMW",
            "FOTO": "/logos_marcas_50x50/logo_BMW.png",
        },
        {
            "ID": "Citroën",
            "NOMBRE": "Citroën",
            "FOTO": "/logos_marcas_50x50/logo_CITROËN.png",
        },
        {
            "ID": "CUPRA",
            "NOMBRE": "CUPRA",
            "FOTO": "/logos_marcas_50x50/logo_CUPRA.png",
        },
        {
            "ID": "Dacia",
            "NOMBRE": "Dacia",
            "FOTO": "/logos_marcas_50x50/logo_DACIA.png",
        },
        {
            "ID": "DFSK",
            "NOMBRE": "DFSK",
            "FOTO": "/logos_marcas_50x50/logo_DFSK.png",
        },
        {
            "ID": "DR AUTOMOBILES",
            "NOMBRE": "DR AUTOMOBILES",
            "FOTO": "/logos_marcas_50x50/logo_DR AUTOMOBILES.png",
        },
        {"ID": "DS", "NOMBRE": "DS", "FOTO": "/logos_marcas_50x50/logo_DS.png"},
        {
            "ID": "Ferrari",
            "NOMBRE": "Ferrari",
            "FOTO": "/logos_marcas_50x50/logo_FERRARI.png",
        },
        {
            "ID": "Fiat",
            "NOMBRE": "Fiat",
            "FOTO": "/logos_marcas_50x50/logo_FIAT.png",
        },
        {
            "ID": "Ford",
            "NOMBRE": "Ford",
            "FOTO": "/logos_marcas_50x50/logo_FORD.png",
        },
        {
            "ID": "Honda",
            "NOMBRE": "Honda",
            "FOTO": "/logos_marcas_50x50/logo_HONDA.png",
        },
        {
            "ID": "Hyundai",
            "NOMBRE": "Hyundai",
            "FOTO": "/logos_marcas_50x50/logo_HYUNDAI.png",
        },
        {
            "ID": "Invicta Electric",
            "NOMBRE": "Invicta Electric",
            "FOTO": "/logos_marcas_50x50/logo_INVICTA ELECTRIC.png",
        },
        {
            "ID": "Jaguar",
            "NOMBRE": "Jaguar",
            "FOTO": "/logos_marcas_50x50/logo_JAGUAR.png",
        },
        {
            "ID": "Jeep",
            "NOMBRE": "Jeep",
            "FOTO": "/logos_marcas_50x50/logo_JEEP.png",
        },
        {
            "ID": "Kia",
            "NOMBRE": "Kia",
            "FOTO": "/logos_marcas_50x50/logo_KIA.png",
        },
        {
            "ID": "Land Rover",
            "NOMBRE": "Land Rover",
            "FOTO": "/logos_marcas_50x50/logo_LAND ROVER.png",
        },
        {
            "ID": "Lexus",
            "NOMBRE": "Lexus",
            "FOTO": "/logos_marcas_50x50/logo_LEXUS.png",
        },
        {
            "ID": "Lynk & Co",
            "NOMBRE": "Lynk & Co",
            "FOTO": "/logos_marcas_50x50/logo_LYNK & CO.png",
        },
        {
            "ID": "Mahindra",
            "NOMBRE": "Mahindra",
            "FOTO": "/logos_marcas_50x50/logo_MAHINDRA.png",
        },
        {
            "ID": "Maserati",
            "NOMBRE": "Maserati",
            "FOTO": "/logos_marcas_50x50/logo_MASERATI.png",
        },
        {
            "ID": "Mazda",
            "NOMBRE": "Mazda",
            "FOTO": "/logos_marcas_50x50/logo_MAZDA.png",
        },
        {
            "ID": "Mercedes",
            "NOMBRE": "Mercedes",
            "FOTO": "/logos_marcas_50x50/logo_MERCEDES.png",
        },
        {
            "ID": "MINI",
            "NOMBRE": "MINI",
            "FOTO": "/logos_marcas_50x50/logo_MINI.png",
        },
        {
            "ID": "Mitsubishi",
            "NOMBRE": "Mitsubishi",
            "FOTO": "/logos_marcas_50x50/logo_MITSUBISHI.png",
        },
        {
            "ID": "Nissan",
            "NOMBRE": "Nissan",
            "FOTO": "/logos_marcas_50x50/logo_NISSAN.png",
        },
        {
            "ID": "Opel",
            "NOMBRE": "Opel",
            "FOTO": "/logos_marcas_50x50/logo_OPEL.png",
        },
        {
            "ID": "Peugeot",
            "NOMBRE": "Peugeot",
            "FOTO": "/logos_marcas_50x50/logo_PEUGEOT.png",
        },
        {
            "ID": "Porsche",
            "NOMBRE": "Porsche",
            "FOTO": "/logos_marcas_50x50/logo_PORSCHE.png",
        },
        {
            "ID": "Renault",
            "NOMBRE": "Renault",
            "FOTO": "/logos_marcas_50x50/logo_RENAULT.png",
        },
        {
            "ID": "SEAT",
            "NOMBRE": "SEAT",
            "FOTO": "/logos_marcas_50x50/logo_SEAT.png",
        },
        {
            "ID": "Skoda",
            "NOMBRE": "Skoda",
            "FOTO": "/logos_marcas_50x50/logo_SKODA.png",
        },
        {
            "ID": "Smart",
            "NOMBRE": "Smart",
            "FOTO": "/logos_marcas_50x50/logo_SMART.png",
        },
        {
            "ID": "SsangYong",
            "NOMBRE": "SsangYong",
            "FOTO": "/logos_marcas_50x50/logo_SSANGYONG.png",
        },
        {
            "ID": "Subaru",
            "NOMBRE": "Subaru",
            "FOTO": "/logos_marcas_50x50/logo_SUBARU.png",
        },
        {
            "ID": "Suzuki",
            "NOMBRE": "Suzuki",
            "FOTO": "/logos_marcas_50x50/logo_SUZUKI.png",
        },
        {
            "ID": "Tesla",
            "NOMBRE": "Tesla",
            "FOTO": "/logos_marcas_50x50/logo_TESLA.png",
        },
        {
            "ID": "Toyota",
            "NOMBRE": "Toyota",
            "FOTO": "/logos_marcas_50x50/logo_TOYOTA.png",
        },
        {
            "ID": "Volkswagen",
            "NOMBRE": "Volkswagen",
            "FOTO": "/logos_marcas_50x50/logo_VOLKSWAGEN.png",
        },
        {
            "ID": "Volvo",
            "NOMBRE": "Volvo",
            "FOTO": "/logos_marcas_50x50/logo_VOLVO.png",
        },
    ],
    "carroceria": [
        {"ID": "CA", "NOMBRE": "Cabrio", "LOGO": "CABRIO"},
        {"ID": "CO", "NOMBRE": "Coupé", "LOGO": "COUPÉ"},
        {"ID": "ES", "NOMBRE": "Familiar", "LOGO": "FAMILIAR"},
        {"ID": "FW", "NOMBRE": "Monovolumen", "LOGO": "MONOVOLUMEN"},
        {
            "ID": "HA",
            "NOMBRE": "Berlina Con Portón",
            "LOGO": "BERLINA CON PORTÓN",
        },
        {"ID": "MC", "NOMBRE": "Minicoche", "LOGO": "MINICOCHE"},
        {
            "ID": "MM",
            "NOMBRE": "Monovolumen Compacto",
            "LOGO": "MONOVOLUMEN COMPACTO",
        },
        {"ID": "OD", "NOMBRE": "Todoterreno", "LOGO": "TODOTERRENO"},
        {"ID": "SA", "NOMBRE": "Sedán", "LOGO": "SEDÁN"},
        {"ID": "TA", "NOMBRE": "Targa", "LOGO": "TARGA"},
    ],
}
  • Related