I'm trying to make my post requests faster because at the moment it takes 3 seconds per post. As I need to iterate it n times it could take hours. So, I started looking for threading, async calls and many others but none solved my problem. Mostly of the problems was due to the fact that I couldn't specify the headers and the params of my post request.
My Python version is 3.6.7
My code:
for i in range(0, 1000):
assetId = jsonAssets[i]['id']
uuidValue = uuid.uuid4()
headers = {'Content-Type': 'application/json',}
params = (('remember_token', '123456'),)
data = ('{{"asset":'
'{{"template":1,'
'"uuid":"{uuidValue}", '
'"assetid":{assetId}}}}}'
.format(uuidValue = uuidValue,
assetId = assetId))
response = requests.post('http://localhost:3000/api/v1/assets', headers=headers, params=params, data=data)
Some of the tries were using:
pool.apply_async
or
ThreadResponse
But I couldn't set headers or params like in the request.post
So, how can I make this post request using this header, params and data faster?
Thanks in advance and sorry for any trouble, this is my first stackoverflow post.