Last active
August 1, 2018 15:13
-
-
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
This file contains 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/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
Example CSV:
https://www.google.com/ 200
https://www.facebook.com/foobar424raboof
http://otherexampleurl.com/ 404
https://otherhttpsexampleurl.com/ 503