Skip to content

Instantly share code, notes, and snippets.

@varnav
Created March 16, 2017 10:41
Show Gist options
  • Save varnav/9e074a8aa3c84361c70f147148d93705 to your computer and use it in GitHub Desktop.
Save varnav/9e074a8aa3c84361c70f147148d93705 to your computer and use it in GitHub Desktop.
POST load testing
#!/usr/bin/python3
# POST load testing script
# Eugene Varnavsky 2017
# MIT License
from urllib.parse import urlencode
from urllib.request import Request, urlopen
import urllib
import _thread
import time
# URL for POST
url = 'http://webserver.local/api/auth'
def mainloop(username, password):
# POST DATA
post_fields = {'UserName': username, 'Password': password}
# 15 attempts
for i in range(15):
try:
print ('Request:', username, ':', password)
request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
except urllib.error.HTTPError as e:
print('Error:', e.code, ':', e.reason)
# Start threads
_thread.start_new_thread(mainloop, ('user1', 'password1'))
_thread.start_new_thread(mainloop, ('user2', 'password2'))
_thread.start_new_thread(mainloop, ('user3', 'password3'))
_thread.start_new_thread(mainloop, ('user4', 'password4'))
_thread.start_new_thread(mainloop, ('user5', 'password5'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment