title: ‘platform’ import disappearing from selenium as a result of my script
body: <p>Linux ip-172-31-36-170 3.10.35-43.137.amzn1.x86_64 #1 SMP Wed Apr 2 09:36:59 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux</p>
  
  <p>Amazon Linux AMI release 2014.03
  cpe:/o:amazon:linux:2014.03:ga</p>
  
  <hr>
  
  <p>I've run into a weird problem with a script that uses selenium.webdriver.PhantomJS. </p>
  
  <p>SYMPTOMS…
  My script uses the following to start a phantomjs session</p>
  
  <pre><code>from selenium import selenium
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.action_chains import ActionChains
  (…)
  def load_driver(self, _driver = "phantomjs", _path = "./phantomjs"):
          if   "phantom" in str(_driver).lower():
              self.driver = webdriver.PhantomJS(_path)
  </code></pre>
  
  <p>Fails with:
      selenium.common.exceptions.WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen</p>
  
  <p>HOWEVER, at the python command line, everything works fine…</p>
  
  <pre><code>from selenium import webdriver
  _path = './phantomjs.exe'
  driver = webdriver.PhantomJS(_path)
  PLATFORM: Linux
  platform.system() != 'Windows':  True
  </code></pre>
  
  <p>(I’ll explain “PLATFORM: Linux”, and “platform.system() != 'Windows':  True” below)</p>
  
  <p>SO…
  I traced the error to the “/usr/lib/python2.6/site-packages/selenium/webdriver/phantomjs/service.py” and specifically this code…</p>
  
  <pre><code>def start(self):
      """
      """
      try:
          print "PLATFORM:", platform.system() #ADDED BY ME
          # FOLLOWING ADDED BY ME, NOW CAUSING THE ERROR
          print "platform.system() != 'Windows': ", platform.system() != 'Windows' 
          self.process = subprocess.Popen(self.service_args, stdin=subprocess.PIPE,
                                          close_fds=platform.system() != 'Windows', # &lt;-- THIS CAUSED ORIG PROB
                                          stdout=self._log, stderr=self._log)
  
      except Exception as e:
          raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
  </code></pre>
  
  <p>AND HERE’S THE ISSUE…
  When I run the code at the python command line (see above) everything is fine, AND the responses to ‘platform.system()’ and “platform.system() != 'Windows' ” are correct. </p>
  
  <p>However, when I run my script, the ‘platform.system()’ reports blank and “platform.system() != 'Windows' ” errors. (See actual output below). </p>
  
  <p>So, for some reason, when my script loads selenium and runs…THE SELENIUM CODE loses the ‘platform’ import. </p>
  
  <p>Thanks for the help!</p>
  
  <p>ACTUAL OUTPUT BELOW (NOTICE that 'PLATFORM:' is followed by 'blank' (instead of 'Linux'), and the next line “platform.system() != 'Windows' ” triggers the error. These lines were added by me into the SELENIUM code, not my code!)</p>
  
  <pre><code>PLATFORM:
  Traceback (most recent call last):
    File "./agmarknet.py", line 834, in &lt;module&gt;
      username  = options.username      # --username
    File "./agmarknet.py", line 124, in __init__
      self.load_driver(driver, driver_path)
    File "./agmarknet.py", line 521, in load_driver
      self.driver = webdriver.PhantomJS(_path)
    File "/usr/lib/python2.6/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 50, in __init__
      self.service.start()
    File "/usr/lib/python2.6/site-packages/selenium/webdriver/phantomjs/service.py", line 64, in start
      print "PLATFORM:", platform.system() #333
    File "/usr/lib64/python2.6/platform.py", line 1272, in system
      return uname()[0]
    File "/usr/lib64/python2.6/platform.py", line 1239, in uname
      processor = _syscmd_uname('-p','')
    File "/usr/lib64/python2.6/platform.py", line 995, in _syscmd_uname
      output = string.strip(f.read())
    File "./agmarknet.py", line 350, in _signal_handler
      self._cleanup()
    File "./agmarknet.py", line 194, in _cleanup
      self.driver.close()
  AttributeError: 'Agmarknet' object has no attribute 'driver'
  2014-05-18 12:42:40,281 - Agmarknet - INFO - Closing WebDriver...
  Error in atexit._run_exitfuncs:
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/atexit.py", line 24, in _run_exitfuncs
      func(*targs, **kargs)
    File "./agmarknet.py", line 194, in _cleanup
      self.driver.close()
  AttributeError: 'Agmarknet' object has no attribute 'driver'
  Error in sys.exitfunc:
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/atexit.py", line 24, in _run_exitfuncs
      func(*targs, **kargs)
    File "./agmarknet.py", line 194, in _cleanup
      self.driver.close()
  </code></pre>