Reputation: 393
I am trying to set up a python script that tests if a server is up, and email me if it is not. I am currently trying to implement just the email portion of that goal.
My code looks like:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os
import time
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.action_chains import ActionChains
from urllib.request import urlopen
from html.parser import HTMLParser
import smtplib
binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path='C:\geckodriver-v0.18.0-win64\geckodriver.exe')
class PythonOrgSearch(unittest.TestCase):
#sets up driver to run tests
def setUp(self):
self.driver = driver
def testServer(self):
driver = self.driver
server = smtplib.SMTP('smtp.gmail.com', 587)
#Next, log in to the server
server.login("[email protected]", "password")
#Send the mail
msg = "Testing if server is down" # The /n separates the message from the headers
server.sendmail("[email protected]", "[email protected]", msg)
driver.close()
if __name__ == "__main__":
unittest.main()
When I run this, I get the error that driver.close() is improper syntax. However, it works fine on every other test script I have. Before this error popped up, the script would just run and never close, and the email would never be sent. I am unsure what I am missing. Please let me know if you see the issue. Thank you!
Upvotes: 1
Views: 342
Reputation: 911
You have open parentheses:
server.sendmail(("[email protected]", "[email protected]", msg)
Change to:
server.sendmail("[email protected]", "[email protected]", msg)
Upvotes: 1