NGuyen NGuyen - 1 year ago 99
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 :)

Answer Source

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

Change data simply by:

data['Name'] = str(i)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download