NGuyen NGuyen - 5 months ago 19
HTTP Question

Python: How to change variable in http post request

data = {'Email':'','Name':'1','Password':'gfgf65jh56456jh67'}
r =, data=json.dumps(data), headers=headers)

I am using above code to send http request and it worked well. However, I want to use for loop to change "Name" variable. So, this is my code after changing

for i in range(1,1000):
data = "{'Email':'','Name':'" + str(i) + "','Password':'gfgf65jh56456jh67'}"
r =, data=json.dumps(data), headers=headers)

However, I got an output from server: {'Message': 'An error has occurred.'}. It is not python error. So, how to fix my code ? Thank you :)


In the line that changes data, data is not a dictionary any more but a string...

Change data simply by:

data['Name'] = str(i)