Skip to content

Instantly share code, notes, and snippets.

@checco
Last active August 1, 2018 15:13
Show Gist options
  • Save checco/174376976201ee5c14071d742f01aeda to your computer and use it in GitHub Desktop.
Save checco/174376976201ee5c14071d742f01aeda to your computer and use it in GitHub Desktop.
Python script that checks the HTTP status code of an URL. You have to write a list of URLs (url_list.csv), with the desired status code on the second column (if the second column is empty it takes a 200 like default value). You can use this script for automatic testing some URLs of your internal/external environment
#!/usr/bin/env python
import requests
file = "url_list.csv"
with open(file, 'r') as f:
for line in f:
line += ' '
url = line.split(' ')[0].strip()
statusCode = line.split(' ')[1].strip()
if not statusCode:
statusCode = '200'
r = requests.get(url)
if r.status_code == int(statusCode):
print '[INFO] ' + url + ' passed the test'
else:
print '[ERROR] ' + url + ' return ' + str(r.status_code) + ' instead of ' + str(statusCode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment