Skip to content

Commit

Permalink
Added new error exception message "Connection timed out" instead of i…
Browse files Browse the repository at this point in the history
…t being caught by the last except.
  • Loading branch information
brett935 committed Jun 16, 2015
1 parent 69f5817 commit 2185d97
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions mailTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ def testAddress(email):
url = 'http://mailtester.com/testmail.php'

data = urllib.urlencode(query_args)
time.sleep(waitTime)######temporary delay between steps for testing

request = urllib2.Request(url, data)
time.sleep(waitTime)######temporary delay between steps for testing


response = urllib2.urlopen(request).read()
time.sleep(waitTime)######temporary delay between steps for testing


searchString=['E-mail address is valid'] #string to search for to detect if the email was valid
errorString=['503 Service Unavailable'] #string to search for to detect a timeout because to many request from same IP address
errorString=['503 Service Unavailable'] #string to search for to detect being blacklisted because to many request from same IP address
cantValidateString=["Server doesn't allow e-mail address verification"] #string to search for to detect if the server doesnt support email validation
timedOutString=['Connection timed out'] #string to search for to detect if the server timed out

if any(x in response for x in searchString):
#print "valid email"
Expand All @@ -39,15 +45,19 @@ def testAddress(email):
cantValidate.append(email)

elif any(x in response for x in errorString):
error = "Server Timeout because to many request from same IP address -"
error += time.asctime() #add timestamp to error message
timeOutError(error + " " + email) #add timeout message to log
input (error + " Press Enter to exit")
input ("Server Blacklisted because to many request from same IP address - Press Enter to exit")
blacklistError(email)
sys.exit(error)

elif any(x in response for x in timedOutString):
timeOutError(error)
time.sleep(5) #wait before next test so hopefully it won't time out too


else:
#print "invalid email"
invalid.append(email)

except urllib2.HTTPError:
saveToFile() #if an error occurs testing an email then save all tested emails up to that point
timeOutError(email) #add email that caused a problem to the error log
Expand Down Expand Up @@ -160,6 +170,11 @@ def unknownError(email):
error = "An unknown error occured: "
error += email + " " + time.asctime()
errorLog(error)

def blacklistError(email):
error = "Server Blacklisted because to many request from same IP address -"
error += time.asctime() #add timestamp to error message
errorLog(error)

def errorLog(error):
e = open( 'errors.txt', 'a')
Expand Down

0 comments on commit 2185d97

Please sign in to comment.