title: Firefox doesn't open when calling Webdriver in Python from PHP script
body: <p>I have a python script calling the selenium webdriver for Firefox. That works fine if I call the Python script from CMD but not when called from a simple PHP page.</p>
  <p>I have tried multiple things and simplified my scripts but no luck.</p>
  <p>A similar script works fine if I host it on my local Windows server. However this does not work when hosted on AWS.</p>
  <p>PHP script:</p>
  <pre><code>$user_name = 'test';
  $short_lang = 'fr';
  
  $pyscript = DIR_PYTHON_SCRIPTS.'retrieve_player_worlds.py';
  $python = 'C:\Python39\python.exe';
  
  $cmd = &quot;$python $pyscript $user_name $short_lang&quot;;
  exec(&quot;$cmd&quot;, $python_output);
  
  return $python_output;
  </code></pre>
  <p>Extract of Python script:</p>
  <pre><code>#!C:/Python39/python.exe
  import sys
  import json
  
  from seleniumwire import webdriver
  from selenium.webdriver.common.by import By
  from selenium.common.exceptions import TimeoutException
  from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  from selenium.webdriver import Firefox
  from selenium.webdriver.firefox.options import Options
  
  opts = Options()
  opts.log.level = &quot;trace&quot;
  
  try:
      binary = FirefoxBinary(r'C:\\Program Files (x86)\\Mozilla Firefox\\Firefox.exe')
      driver = webdriver.Firefox(firefox_binary=binary, executable_path='C:\\xampp\\htdocs\\path\\scripts\\python\\geckodriver.exe', options=opts)
      driver.get('https://www.google.se')   # tried different URLs
      driver.maximize_window()
  
  except Exception as e:
      logging.exception(&quot;Exception occurred binary firefox&quot;)
  
  driver.quit()
  </code></pre>
  <p>geckodriver logs:</p>
  <pre><code>606076677289    geckodriver INFO    Listening on 127.0.0.1:50050
  1606076680370   mozrunner::runner   INFO    Running command: &quot;C:\\\\Program Files (x86)\\\\Mozilla Firefox\\\\Firefox.exe&quot; &quot;--marionette&quot; &quot;--headless&quot; &quot;-foreground&quot; &quot;-no-remote&quot; &quot;-profile&quot; &quot;C:\\Windows\\TEMP\\rust_mozprofileQQJMxG&quot;
  1606076680370   geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1:50058
  *** You are running in headless mode.
  1606076685899   Marionette  TRACE   Marionette enabled
  1606076685955   Marionette  TRACE   Received observer notification toplevel-window-ready
  JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
  console.warn: SearchSettings: &quot;get: No settings file exists, new profile?&quot; (new Error(&quot;&quot;, &quot;(unknown module)&quot;))
  1606076688307   Marionette  TRACE   Received observer notification marionette-startup-requested
  1606076688308   Marionette  TRACE   Waiting until startup recorder finished recording startup scripts...
  1606076688323   Marionette  TRACE   All scripts recorded.
  1606076688323   Marionette  DEBUG   Setting recommended pref apz.content_response_timeout to 60000
  1606076688323   Marionette  DEBUG   Setting recommended pref browser.contentblocking.introCount to 99
  1606076688323   Marionette  DEBUG   Setting recommended pref browser.download.panel.shown to true
  1606076688323   Marionette  DEBUG   Setting recommended pref browser.newtabpage.enabled to false
  1606076688324   Marionette  DEBUG   Setting recommended pref browser.pagethumbnails.capturing_disabled to true
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.search.update to false
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.tabs.disableBackgroundZombification to false
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.tabs.remote.separatePrivilegedContentProcess to false
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.tabs.unloadOnLowMemory to false
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.tabs.warnOnCloseOtherTabs to false
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.tabs.warnOnOpen to false
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.usedOnWindows10.introURL to 
  1606076688325   Marionette  DEBUG   Setting recommended pref browser.urlbar.suggest.searches to false
  1606076688326   Marionette  DEBUG   Setting recommended pref datareporting.policy.dataSubmissionPolicyAccepted to false
  1606076688326   Marionette  DEBUG   Setting recommended pref dom.disable_beforeunload to true
  1606076688326   Marionette  DEBUG   Setting recommended pref dom.disable_open_during_load to false
  1606076688326   Marionette  DEBUG   Setting recommended pref dom.file.createInChild to true
  1606076688326   Marionette  DEBUG   Setting recommended pref dom.max_chrome_script_run_time to 0
  1606076688326   Marionette  DEBUG   Setting recommended pref dom.max_script_run_time to 0
  1606076688327   Marionette  DEBUG   Setting recommended pref dom.push.connection.enabled to false
  1606076688327   Marionette  DEBUG   Setting recommended pref extensions.getAddons.cache.enabled to false
  1606076688327   Marionette  DEBUG   Setting recommended pref extensions.getAddons.discovery.api_url to data:, 
  1606076688327   Marionette  DEBUG   Setting recommended pref network.http.prompt-temp-redirect to false
  1606076688327   Marionette  DEBUG   Setting recommended pref privacy.trackingprotection.enabled to false
  1606076688328   Marionette  DEBUG   Setting recommended pref security.fileuri.strict_origin_policy to false
  1606076688328   Marionette  DEBUG   Setting recommended pref security.notification_enable_delay to 0
  1606076688328   Marionette  DEBUG   Setting recommended pref signon.autofillForms to false
  1606076688329   Marionette  DEBUG   Setting recommended pref signon.rememberSignons to false
  1606076688332   Marionette  INFO    Listening on port 50058
  1606076688333   Marionette  DEBUG   Marionette is listening
  1606076688806   Marionette  DEBUG   Accepted connection 0 from 127.0.0.1:50080
  1606076688798   geckodriver::marionette DEBUG   Connection to Marionette established on 127.0.0.1:50058.
  1606076688822   Marionette  DEBUG   0 -&gt; [0,1,&quot;WebDriver:NewSession&quot;,{&quot;acceptInsecureCerts&quot;:true,&quot;browserName&quot;:&quot;firefox&quot;,&quot;proxy&quot;:{&quot;httpProxy&quot;:&quot;127.0.0.1:50048&quot;,&quot;noProxy&quot;:[],&quot;proxyType&quot;:&quot;manual&quot;,&quot;sslProxy&quot;:&quot;127.0.0.1:50048&quot;}}]
  1606076688823   Marionette  WARN    TLS certificate errors will be ignored for this session
  1606076688826   Marionette  INFO    Proxy settings initialised: {&quot;proxyType&quot;:&quot;manual&quot;,&quot;httpProxy&quot;:&quot;127.0.0.1:50048&quot;,&quot;noProxy&quot;:[],&quot;sslProxy&quot;:&quot;127.0.0.1:50048&quot;}
  1606076688837   Marionette  TRACE   [21] Frame script loaded
  1606076688886   Marionette  DEBUG   0 &lt;- [1,1,null,{&quot;sessionId&quot;:&quot;f9a971f5-6890-48f2-b7ad-c0d63583e907&quot;,&quot;capabilities&quot;:{&quot;browserName&quot;:&quot;firefox&quot;,&quot;browserVersion&quot;:&quot;83.0&quot; ... \rust_mozprofileQQJMxG&quot;,&quot;moz:shutdownTimeout&quot;:60000,&quot;moz:useNonSpecCompliantPointerOrigin&quot;:false,&quot;moz:webdriverClick&quot;:true}}]
  1606076688892   webdriver::server   DEBUG   &lt;- 200 OK {&quot;value&quot;:{&quot;sessionId&quot;:&quot;f9a971f5-6890-48f2-b7ad-c0d63583e907&quot;,&quot;capabilities&quot;:{&quot;acceptInsecureCerts&quot;:true,&quot;browserName&quot;:&quot;firefox&quot;,&quot;browserVersion&quot;:&quot;83.0&quot;,&quot;moz:accessibilityChecks&quot;:false,&quot;moz:buildID&quot;:&quot;20201112153044&quot;,&quot;moz:geckodriverVersion&quot;:&quot;0.28.0&quot;,&quot;moz:headless&quot;:true,&quot;moz:processID&quot;:7724,&quot;moz:profile&quot;:&quot;C:\\Windows\\Temp\\rust_mozprofileQQJMxG&quot;,&quot;moz:shutdownTimeout&quot;:60000,&quot;moz:useNonSpecCompliantPointerOrigin&quot;:false,&quot;moz:webdriverClick&quot;:true,&quot;pageLoadStrategy&quot;:&quot;normal&quot;,&quot;platformName&quot;:&quot;windows&quot;,&quot;platformVersion&quot;:&quot;10.0&quot;,&quot;proxy&quot;:{&quot;httpProxy&quot;:&quot;127.0.0.1:50048&quot;,&quot;noProxy&quot;:[],&quot;proxyType&quot;:&quot;manual&quot;,&quot;sslProxy&quot;:&quot;127.0.0.1:50048&quot;},&quot;rotatable&quot;:false,&quot;setWindowRect&quot;:true,&quot;strictFileInteractability&quot;:false,&quot;timeouts&quot;:{&quot;implicit&quot;:0,&quot;pageLoad&quot;:300000,&quot;script&quot;:30000},&quot;unhandledPromptBehavior&quot;:&quot;dismiss and notify&quot;}}}
  1606076688892   webdriver::server   DEBUG   -&gt; POST /session/f9a971f5-6890-48f2-b7ad-c0d63583e907/url {&quot;url&quot;: &quot;https://www.google.se&quot;}
  1606076688902   Marionette  DEBUG   0 -&gt; [0,2,&quot;WebDriver:Navigate&quot;,{&quot;url&quot;:&quot;https://www.google.se&quot;}]
  1606076688916   Marionette  TRACE   Received message beforeunload for about:blank
  1606076691334   Marionette  TRACE   Received message beforeunload for about:blank
  1606076691341   Marionette  TRACE   Received message pagehide for about:blank
  1606076691406   Marionette  TRACE   Received message DOMContentLoaded for about:neterror?e=nssFailure2&amp;u=https%3A//www.google.se/&amp;c=UTF-8&amp;d=Anslutningen%20till%20www.google.se%20avbr%C3%B6ts%20under%20h%C3%A4mtningen%20av%20sidan.
  1606076691407   Marionette  DEBUG   0 &lt;- [1,2,{&quot;error&quot;:&quot;unknown error&quot;,&quot;message&quot;:&quot;Reached error page: about:neterror?e=nssFailure2&amp;u=https%3A//www.google.se/&amp;c=UTF-8&amp; ... adyState@chrome://marionette/content/navigate.js:60:24\nonNavigation@chrome://marionette/content/navigate.js:285:39\n&quot;},null]
  1606076691409   webdriver::server   DEBUG   &lt;- 500 Internal Server Error {&quot;value&quot;:{&quot;error&quot;:&quot;unknown error&quot;,&quot;message&quot;:&quot;Reached error page: about:neterror?e=nssFailure2&amp;u=https%3A//www.google.se/&amp;c=UTF-8&amp;d=Anslutningen%20till%20www.google.se%20avbr%C3%B6ts%20under%20h%C3%A4mtningen%20av%20sidan.&quot;,&quot;stacktrace&quot;:&quot;WebDriverError@chrome://marionette/content/error.js:181:5\nUnknownError@chrome://marionette/content/error.js:488:5\ncheckReadyState@chrome://marionette/content/navigate.js:60:24\nonNavigation@chrome://marionette/content/navigate.js:285:39\n&quot;}}                                                                                                                                                                                                                                        
  1606076691440   Marionette  DEBUG   Closed connection 0
  </code></pre>
  <p>I have Googled the errors for a few days now but nothing has helped. I seems that the connection has been aborted at some point.</p>
  <p><code>geckodriver.exe</code> is in the right folder (<code>C:\\xampp\\htdocs\\path\\scripts\\python\\</code>) and permissions seem to be okay as the log file is created by the script.
  I'm using the latest version of Firefox, webdriver (0.28) and Selenium.</p>
  <p><strong>Additional information (as requested in comments below):</strong>
  After calling the webdriver, I interact with elements in the page and enter credentials:</p>
  <pre><code>iframe = driver.find_element_by_tag_name('iframe')
  iframe_switched = driver.switch_to.frame(iframe)
      
  useridInput = driver.find_element_by_id('login_userid')
  useridInput.click();
      
  useridInput.send_keys(user_name); 
  </code></pre>
  <p><strong>Update 2:</strong></p>
  <p>I compared the geckodriver logs when I run from CMD and from the PHP page. The difference is only in the end, everything else (including the command) is the same:</p>
  <pre><code>1606076691406   Marionette  TRACE   Received message DOMContentLoaded for about:neterror?e=nssFailure2&amp;u=https%3A//www.google.se/&amp;c=UTF-8&amp;d=Anslutningen%20till%20www.google.se%20avbr%C3%B6ts%20under%20h%C3%A4mtningen%20av%20sidan.
  1606076691407   Marionette  DEBUG   0 &lt;- [1,2,{&quot;error&quot;:&quot;unknown error&quot;,&quot;message&quot;:&quot;Reached error page: about:neterror?e=nssFailure2&amp;u=https%3A//www.google.se/&amp;c=UTF-8&amp; ... adyState@chrome://marionette/content/navigate.js:60:24\nonNavigation@chrome://marionette/content/navigate.js:285:39\n&quot;},null]
  1606076691409   webdriver::server   DEBUG   &lt;- 500 Internal Server Error {&quot;value&quot;:{&quot;error&quot;:&quot;unknown error&quot;,&quot;message&quot;:&quot;Reached error page: about:neterror?e=nssFailure2&amp;u=https%3A//www.google.se/&amp;c=UTF-8&amp;d=Anslutningen%20till%20www.google.se%20avbr%C3%B6ts%20under%20h%C3%A4mtningen%20av%20sidan.&quot;,&quot;stacktrace&quot;:&quot;WebDriverError@chrome://marionette/content/error.js:181:5\nUnknownError@chrome://marionette/content/error.js:488:5\ncheckReadyState@chrome://marionette/content/navigate.js:60:24\nonNavigation@chrome://marionette/content/navigate.js:285:39\n&quot;}}                                                                                                                                                                                              
  1606076691440   Marionette  DEBUG   Closed connection 0
  </code></pre>
  <p>Decoded and translated, this means:
  <code>The connection to www.google.com was terminated while downloading the page</code></p>