1

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!

1 Answer 1

1

You have open parentheses:

server.sendmail(("[email protected]", "[email protected]", msg)

Change to:

server.sendmail("[email protected]", "[email protected]", msg)
Sign up to request clarification or add additional context in comments.

4 Comments

I fixed that issue, however I am still getting the same issue regarding the driver.close()
You are still getting an invalid syntax error or is your code throwing an exception? What is the error message?
There is no error per say. The code "runs" or rather it appears to in the terminal, except it never stops and the email is never sent. It's as though the script opens but then doesn't do anything or close
Sorry to clarify I did end up fixing the driver.close(), but can't get the email functionality to work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.