Saturday, June 4, 2022

[SOLVED] Python: Replace Python text - CURL Python

Issue

I need the variable defined as NUEMRODEDNI to be tempered, how is it done?

Excuse me I'm a newbie

I don't know how to use a variable defined in python, I need it to be replaced as shown in the image

import string

import requests

from requests.structures import CaseInsensitiveDict



url = "www.url.com:8022/SistemaIdentificacion/servlet/com.personas.consultapersona?030bf8cfcd4bfccbd543df61b1b43f67,gx-no-cache=1648440596691"



NUEMRODEDNI = "41087712"



headers = CaseInsensitiveDict()

headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0"

headers["Accept"] = "*/*"

headers["Accept-Language"] = "es-AR,es;q=0.8,en-US;q=0.5,en;q=0.3"

headers["Accept-Encoding"] = "gzip, deflate"

headers["GxAjaxRequest"] = "1"

headers["Content-Type"] = "application/json"

headers["AJAX_SECURITY_TOKEN"] = "a6da9873adb..."

headers["X-GXAUTH-TOKEN"] = "eyJ0eXAiOiJ..."

headers["Origin"] = "http://www.url.com"

headers["Connection"] = "keep-alive"

headers["Referer"] = "www.url.com/SistemaIdentificacion/servlet/com.personas.consultapersona"

headers["Cookie"] = "GX_CLIENT_ID=0496f100-9e4e-4e36-a68d-ba3770ee2bff; GX_SESSION_ID=KUqyHU%2FZbpu96sYlj7Gry8bCYpV6CaSgVk0BLxVCpAU%3D; JSESSIONID=1812E6AC00940BDB325EF9592CB93FF8; GxTZOffset=America/Argentina/Buenos_Aires"



data = '{"MPage":false,"cmpCtx":"","parms":[EDIT HERE,{"s":"M","v":[["","(None)"],["F","Femenino"],["M","Masculino"]]},"M",{"User":"","CompanyCode":0,"Profile":"","UsrOneLoginID":"6647","Depid":1,"UsrLP":6488,"unidad":"","unidadid":"68","IMFParteCuerpo":"","denunciasid":0,"destino":"68","TipoPersona":"","NombreArchivo":"","denorigen":"","macdestinoscodorganigrama":""}],"hsh":[],"objClass":"consultapersona","pkgName":"com.personas","events":["ENTER"],"grids":{}}'





resp = requests.post(url, headers=headers, data=data)



print(resp.content)

Solution

Please provide your code typed out rather than a screenshot of it, so that we can simply copy & run it on our end.

Nontheless you should try:

NUMERODNI = "41087712"
data = '{"MPage":false,"cmpCtx":"","parms":[EDIT HERE,{"s":"M","v":[["","(None)"],["F","Femenino"],["M","Masculino"]]},"M",{"User":"","CompanyCode":0,"Profile":"","UsrOneLoginID":"6647","Depid":1,"UsrLP":6488,"unidad":"","unidadid":"68","IMFParteCuerpo":"","denunciasid":0,"destino":"68","TipoPersona":"","NombreArchivo":"","denorigen":"","macdestinoscodorganigrama":""}],"hsh":[],"objClass":"consultapersona","pkgName":"com.personas","events":["ENTER"],"grids":{}}'

data = data.replace("EDIT HERE", NUMERODNI)

print(data) # '{... "parms":[41087712, ...}'

This solution definetly delivers the desired string as result. If your code still does not do what you would like it to, then the actual issue has to be somewhere else.



Answered By - Bialomazur
Answer Checked By - David Goodson (WPSolving Volunteer)