title: Error while using Firefox headless, Selenium and Python
body: <p>I am trying to use firefox headless, Selenium framework and Python to fetch webpage on Amazon EC2 Ubuntu linux. My code looks like this:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.firefox.options import Options
  
  options = Options()
  options.headless = True
  
  driver = webdriver.Firefox(options=options,executable_path='/home/ubuntu/geckodriver')
  driver.get(&quot;https://google.com&quot;)
  print('Done')
  driver.quit()
  </code></pre>
  <p>Now when I run this, I get the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;test1.py&quot;, line 7, in &lt;module&gt;
      driver = webdriver.Firefox(options=options,executable_path='/home/ubuntu/geckodriver')
    File &quot;/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py&quot;, line 170, in __init__
      RemoteWebDriver.__init__(
    File &quot;/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py&quot;, line 157, in __init__
      self.start_session(capabilities, browser_profile)
    File &quot;/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py&quot;, line 252, in start_session
      response = self.execute(Command.NEW_SESSION, parameters)
    File &quot;/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py&quot;, line 321, in execute
      self.error_handler.check_response(response)
    File &quot;/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py&quot;, line 242, in check_response
      raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.TimeoutException: Message: Connection refused (os error 111)
  </code></pre>
  <p>I have made sure that my geckodriver and firefox versions are compatible, I have tried rebooting my EC2 instance but nothing is working.</p>
  <p>Any help is appreciated.</p>