title: 'Connection aborted.', ConnectionResetError(104, 'Connection reset by peer') using Selenium with ChromeDriver and Chrome through Python
body: <p>The code below is executed in a loop, where 10-15 local .html files are opened and an image of each is saved as a .png. </p>
  
  <ul>
  <li>Ubuntu Server 16.04 </li>
  <li>ChromeDriver  2.41.578700  </li>
  <li>Google Chrome 74.0.3729.108</li>
  <li>selenium 3.141.0</li>
  <li>Python 3.6</li>
  </ul>
  
  <p>The first two files are opened and the image is saved, however the rest result in: </p>
  
  <blockquote>
    <p>('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))</p>
  </blockquote>
  
  <p>The paths to the files are all correct and changing the order of the images to be saved does not make a difference.</p>
  
  <pre><code>def _save_image(html_file_path, png_file_path, h=850, w=833):
      try:
          from selenium import webdriver
          from selenium.webdriver.chrome.options import Options
      except Exception as ex:
          raise Exception("Saving the plot as a .PNG requires *selenium* package to be installed. Please install selenium using *pip install selenium*.")
  
      options = Options()
      options.add_argument('--headless')
      options.add_argument('disable-infobars')
      options.add_argument('--disable-extensions')
      options.add_argument('--no-sandbox')
      options.add_argument('--disable-dev-shm-usage')
      #options.add_argument('--disable-gpu')
  
      if os.name == 'nt':
          chrome_driver_path = os.path.dirname(__file__)
          chrome_driver_path = chrome_driver_path[:-3] + "chromedriver.exe"
      elif os.name == 'posix':
          chrome_driver_path = "/usr/bin/chromedriver"
      else:
          raise Exception("OS could not be detected, thus selenium could not be initialised properly.")
      driver = webdriver.Chrome(chrome_driver_path, chrome_options=options)
      driver.set_window_size(w, h)
      driver.get("file://"+html_file_path)
      time.sleep(5)
      driver.save_screenshot(png_file_path + ".png")
      driver.quit()
      time.sleep(5)
  </code></pre>
  
  <p>The time.sleep(5) was added to check if the error was due to the page taking long to load, increased it to 30 seconds and the result was the same. The import statements are within the function due to a technical requirement which will be sorted at a later stage.</p>