Forums

PhantomJS error

Hi,

Yes i know what you are thinking, PhantomJS has been asked about a lot, however i cannot seem to find anything on the particluar error that i am getting.

background: - I am trying to run a Flask web application that uses PhantomJS web driver to scrape a web page and output the results to the site.

I have put the linux executable (not sure if that is the right word for linux) in a bin folder and pointed my code to it, however i get the following error: -

"selenium.common.exceptions.WebDriverException: Message: 'bin' executable may have wrong permissions."

Not sure if it possible to have an admin give the server access to that folder? or even if that is the real issue.

Could someone please shed some light on this issue?

Thankyou, Justin

What happens if you just chmod it 777?

Thanks for the reply, i just ran chmod 777 to the path and that seems to have fixed the permission issue, however now i am getting another Selenium error that states:

2016-10-14 08:01:31,141 :AttributeError: 'Service' object has no attribute 'process'

Is there a longer stack trace that you could share with us?

Sorry yes that would probably help, this is the stacktrace, looks like the error has come back

2016-10-15 06:22:23,295 :Exception on /account [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 62, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/jussodev/mysite/views.py", line 38, in accInfo
    accbal=getAccBal()
  File "/home/jussodev/mysite/views.py", line 13, in getAccBal
    browser = webdriver.PhantomJS("/home/jussodev/mysite/bin")
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'bin' executable may have wrong permissions.

[edited by admin: formatting]

Are you sure that fixed the issue? I still see the 'bin' is not executable error in your stack trace. Did you restart your webapp after making the changes?

Yes I always restart the web app after any changes are made.

Just to clarify sorry I got another error after the permission error but then it came back, that last stack track is the most recent error. Not sure how it came back after the other error as no code changes were made.

And is the most up to date error still showing this? (the error you showed is ~5hrs old?)

Yeah that's because I'm not going to keep trying obviously when it isn't working, heres a fresh message:

2016-10-15 11:43:24,108 :Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7f6a0f81a940>>
2016-10-15 11:43:24,123 :Traceback (most recent call last):
2016-10-15 11:43:24,123 :  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 151, in __del__
2016-10-15 11:43:24,124 :    self.stop()
2016-10-15 11:43:24,124 :  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 123, in stop
2016-10-15 11:43:24,125 :    if self.process is None:
2016-10-15 11:43:24,125 :AttributeError: 'Service' object has no attribute 'process'
2016-10-15 11:43:26,667 :Exception on /account [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 62, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/jussodev/mysite/views.py", line 38, in accInfo
    accbal=getAccBal()
  File "/home/jussodev/mysite/views.py", line 13, in getAccBal
    browser = webdriver.PhantomJS("/home/jussodev/mysite/bin")
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'bin' executable may have wrong permissions.

[edited by admin: formatting]

quick check- can you run the same thing from a console?

No, i've tried and i get the same permission error. I have gone to the directory listed above /home/jussodev/mysite and also /home/jussodev/mysite/bin and tried to chmod 777 the mentioned directories and it throws the following error:

chmod -r -v 777 /home/jussodev/mysite chmod: cannot access ‘777’: No such file or directory

not sure if the directory name should be something more specific, sorry for my ignorance with Linux, i've been a windows Administrator all my life.

Thankyou for your help so far

I think you are looking for chmod -R instead of -r.

The -r means take away read permissions from the target.

See if that works?

Thanks for your help so far Conrad, i just tried to chmod -R 777 to the directory and it let me do it, however the traceback for the error stacktrace indicates the permission error is coming from the python3.5 folder (see above) so i tried chmod 777 to that directory, and it throws the following error, also tried sudo, that didnt work either

chmod: changing permissions of ‘/usr/lib/python3.5/posixpath.py’: Operation not permitted 06:06 /usr/lib $ ^C 06:06 /usr/lib $ sudo chmod -R 777 /usr/lib/python3.5 sudo: unknown user: root sudo: unable to initialize policy plugin 06:06 /usr/lib $

note, the entire python3.5 folder throws the "Operation not permitted" error

Ah! My colleagues just reminded me that we don't support phantomjs in selenium (but firefox + selenium works).