Skip to content

Instantly share code, notes, and snippets.

@rafaelnovello
Created June 5, 2023 19:19
Show Gist options
  • Save rafaelnovello/5668cd3726ef7a93fbcb3f44feca2cf2 to your computer and use it in GitHub Desktop.
Save rafaelnovello/5668cd3726ef7a93fbcb3f44feca2cf2 to your computer and use it in GitHub Desktop.
import urllib3
import requests
from collections import defaultdict
from concurrent.futures import ThreadPoolExecutor
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def test(url, report):
res = requests.get(url, headers = {'User-agent': 'your bot 0.1'}, verify=False)
if res.status_code == 200:
report['success'].append(res)
elif res.status_code == 500:
report['err500'].append(res)
else:
report['error'].append(res)
def stress_test(url, num_req):
report = defaultdict(list)
executor = ThreadPoolExecutor(max_workers=10)
for i in range(num_req):
executor.submit(test, url, report)
executor.shutdown()
return report
report = stress_test("http://www.google.com", 1000)
print(len(report['success']))
print(len(report['err500']))
print(len(report['error']))
print(report['err500'][0].content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment