2

I'm trying to close the browser and reopen it after a loop

class Bot():

driver = webdriver.Chrome(options=chrome_options)

    def __init__(self):
        self.openyoutube
        self.quitbrowser()

    def openyoutube(self):
        self.driver.get('https://www.youtube.com')
        sleep(5)
   
    def quitbrowser(self):
        self.driver.quit()



def main():
    while True: 
        my_bot = Bot()
        sleep(15)

if __name__ == '__main__':
    main()

But once it tries to start all over, it throws this error:

raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=64578): Max retries exceeded with url: /session/f7fcdfe14c3e2c75d530b3cbf70348d2/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb6d71f8250>: Failed to establish a new connection: [Errno 61] Connection refused'))

1 Answer 1

1
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=64578): Max retries exceeded with url: /session/f7fcdfe14c3e2c75d530b3cbf70348d2/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb6d71f8250>: Failed to establish a new connection: [Errno 61] Connection refused'))

Generally after this error we reinitialise the driver which you can do by using a try catch for Maxretryerror.

driver = webdriver.Chrome(options=chrome_options)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the response, I tried to catch the MaxRetryError, but still getting the same error. Do I need to import something? Please show an example of how to catch the error. I might be doing it the wrong way.
Post the way you are doing

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.