Created
March 16, 2017 10:41
-
-
Save varnav/9e074a8aa3c84361c70f147148d93705 to your computer and use it in GitHub Desktop.
POST load testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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