AttributeError: 'Service' object has no attribute 'process' - python

I'm trying to take screenshot of a webpage using Selenium webdriver, but cannot get it to work. I've added firefox as a Path environment variable and rebooted my system, added specified the path of the Geckodriver, even tried doing the same with Chromedriver, but nothing seems to work. The code I've used is added below
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:\Program Files\Mozilla Firefox')
browser = webdriver.Firefox(executable_path=r'C:\Users\ris09\Desktop\ChessReader\geckodriver-v0.32.0-win32', firefox_binary=binary)
Here's the error message that I'm getting:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_15324\3615299261.py in
2
3 binary = FirefoxBinary('C:\Program Files\Mozilla Firefox')
----> 4 browser = webdriver.Firefox(executable_path=r'C:\Users\ris09\Desktop\ChessReader\geckodriver-v0.32.0-win32', firefox_binary=binary)
C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\firefox\webdriver.py in init(self, firefox_profile, firefox_binary, capabilities, proxy, executable_path, options, service_log_path, service_args, service, desired_capabilities, log_path, keep_alive)
190 if not self.service:
191 self.service = Service(executable_path, service_args=service_args, log_path=service_log_path)
--> 192 self.service.start()
193
194 executor = FirefoxRemoteConnection(
C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py in start(self)
102 count = 0
103 while True:
--> 104 self.assert_process_still_running()
105 if self.is_connectable():
106 break
C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py in assert_process_still_running(self)
113 def assert_process_still_running(self) -> None:
114 """Check if the underlying process is still running."""
--> 115 return_code = self.process.poll()
116 if return_code:
117 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
AttributeError: 'Service' object has no attribute 'process'

Related

Splinter error TypeError: NoneType not callable

I am trying to run the simplest splinter script:
from splinter import Browser
executable_path = {
"executable_path": r"C:\Users\angel\chromedriver.exe"
}
print(executable_path)
browser = Browser('chrome', **executable_path, headless=False)
but keep getting this output:
{'executable_path': 'C:\\Users\\angel\\chromedriver.exe'}
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In [2], line 8
3 executable_path = {
4 "executable_path": r"C:\Users\angel\chromedriver.exe"
5 }
6 print(executable_path)
----> 8 browser = Browser('chrome', **executable_path, headless=False)
File C:\Python310\lib\site-packages\splinter\browser.py:121, in Browser(driver_name, retry_count, *args, **kwargs)
118 except KeyError:
119 raise DriverNotFoundError("No driver for %s" % driver_name)
--> 121 return get_driver(driver, retry_count=retry_count, *args, **kwargs)
File C:\Python310\lib\site-packages\splinter\browser.py:92, in get_driver(driver, retry_count, *args, **kwargs)
90 for _ in range(retry_count):
91 try:
---> 92 return driver(*args, **kwargs)
93 except driver_exceptions as e:
94 err = e
TypeError: 'NoneType' object is not callable
I have research a lot and tried different things. I am sure that I have the correct driver for my chrome version. I am also sure that I have the .exe in that path I am providing.
What can be wrong?

Selenium webdriver -> closing my chrome after one second

I have issue with selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Google\\Chrome Beta\\Application\\chrome.exe"
driver = webdriver.Chrome(options = options, executable_path=r'C:\\Users\\Mariusz\\anaconda3\\envs\\pgg\\Lib\\site-packages\\chromedriver_binary\\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked successfully")
driver.quit()
import chromedriver_binary
wd = wd.Chrome()
wd.implicitly_wait(10)
Above code starting my Chrome for 1 second and then immediately close.
I have feedback in Anaconda:
Chrome Browser Invoked successfully
And debug:
WebDriverException Traceback (most recent call
last) Input In [25], in <cell line: 12>()
9 driver.quit()
10 import chromedriver_binary
---> 12 wd = wd.Chrome()
13 wd.implicitly_wait(10)
File
~\anaconda3\envs\pgg\lib\site-packages\selenium\webdriver\chrome\webdriver.py:76,
in WebDriver.__init__(self, executable_path, port, options,
service_args, desired_capabilities, service_log_path, chrome_options,
keep_alive)
73 self.service.start()
75 try:
---> 76 RemoteWebDriver.__init__(
77 self,
78 command_executor=ChromeRemoteConnection(
79 remote_server_addr=self.service.service_url,
80 keep_alive=keep_alive),
81 desired_capabilities=desired_capabilities)
82 except Exception:
83 self.quit()
File
~\anaconda3\envs\pgg\lib\site-packages\selenium\webdriver\remote\webdriver.py:157,
in WebDriver.__init__(self, command_executor, desired_capabilities,
browser_profile, proxy, keep_alive, file_detector, options)
154 if browser_profile is not None:
155 warnings.warn("Please use FirefoxOptions to set browser profile",
156 DeprecationWarning, stacklevel=2)
--> 157 self.start_session(capabilities, browser_profile)
158 self._switch_to = SwitchTo(self)
159 self._mobile = Mobile(self)
File
~\anaconda3\envs\pgg\lib\site-packages\selenium\webdriver\remote\webdriver.py:252,
in WebDriver.start_session(self, capabilities, browser_profile)
249 w3c_caps = _make_w3c_caps(capabilities)
250 parameters = {"capabilities": w3c_caps,
251 "desiredCapabilities": capabilities}
--> 252 response = self.execute(Command.NEW_SESSION, parameters)
253 if 'sessionId' not in response:
254 response = response['value']
File
~\anaconda3\envs\pgg\lib\site-packages\selenium\webdriver\remote\webdriver.py:321,
in WebDriver.execute(self, driver_command, params)
319 response = self.command_executor.execute(driver_command, params)
320 if response:
--> 321 self.error_handler.check_response(response)
322 response['value'] = self._unwrap_value(
323 response.get('value', None))
324 return response
File
~\anaconda3\envs\pgg\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242,
in ErrorHandler.check_response(self, response)
240 alert_text = value['alert'].get('text')
241 raise exception_class(message, screen, stacktrace, alert_text)
--> 242 raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: cannot find Chrome binary
I think that I've declared chrome binary there:
options.binary_location = "C:\\Program Files\\Google\\Chrome Beta\\Application\\chrome.exe"
Ok I fixed this by remove last lines:
driver.quit()
import chromedriver_binary
wd = wd.Chrome()
wd.implicitly_wait(10)

Selenium problem in VS Code Interactive Mode

I am trying to run Selenium from the interactive mode of Visual Studio code, but I am getting the error below. Everything works great in Jupyter or when I run the script non-interactively.
MRE
# %%
from selenium import webdriver
url = 'google.com'
driver = webdriver.Firefox()
driver.get(url)
Error message
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
++redacted++.py in
3 url = 'google.com'
----> 4 driver = webdriver.Firefox()
5 driver.get(url)
~/anaconda3/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, options, service_log_path, firefox_options, service_args, desired_capabilities, log_path, keep_alive)
168 executor = FirefoxRemoteConnection(
169 remote_server_addr=self.service.service_url)
--> 170 RemoteWebDriver.__init__(
171 self,
172 command_executor=executor,
~/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
155 warnings.warn("Please use FirefoxOptions to set browser profile",
156 DeprecationWarning, stacklevel=2)
--> 157 self.start_session(capabilities, browser_profile)
158 self._switch_to = SwitchTo(self)
159 self._mobile = Mobile(self)
~/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py in start_session(self, capabilities, browser_profile)
250 parameters = {"capabilities": w3c_caps,
251 "desiredCapabilities": capabilities}
--> 252 response = self.execute(Command.NEW_SESSION, parameters)
253 if 'sessionId' not in response:
254 response = response['value']
~/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
319 response = self.command_executor.execute(driver_command, params)
320 if response:
--> 321 self.error_handler.check_response(response)
322 response['value'] = self._unwrap_value(
323 response.get('value', None))
~/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
240 alert_text = value['alert'].get('text')
241 raise exception_class(message, screen, stacktrace, alert_text)
--> 242 raise exception_class(message, screen, stacktrace)
243
244 def _value_or_default(self, obj, key, default):
WebDriverException: Message: Process unexpectedly closed with status 11
Edit 1:
Adding a screenshot of available environments
The first complain about ipykernel not being installed, even though it should be according to pip. The last two give the error

WebDriverException: Message: chrome not reachable When it was working a minute before

I'm writing a scraper using Selenium, and it was working just fine until 15 minutes ago..
All of sudden, I get the following error every time I execute. This is my code:
searchDate = wait.until(EC.element_to_be_clickable((By.XPATH, "/input[#placeholder='select sold date range']")))
searchDate.click()
time.sleep(5)
And the error:
WebDriverException: Message: chrome not reachable
(Session info: chrome=80.0.3987.163)
And my chrome setting:
options = webdriver.ChromeOptions()
prefs = {'download.default_directory': new_dir}
options.add_experimental_option('prefs', prefs)
browser = webdriver.Chrome(executable_path = r'C:/Program Files/chromedriver/chromedriver.exe')
I tried to solve the problem by chain the options as other post suggested, such as:
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
prefs = {'download.default_directory': new_dir}
options.add_experimental_option('prefs', prefs)
browser = webdriver.Chrome(executable_path = r'C:/Program Files/chromedriver/chromedriver.exe', chrome_options=options)
But I still get the exact same error. Why did it happen?
Any advice will be greatly appreciated!
++
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-102-c7d533e1df88> in <module>
----> 1 wait.until(EC.visibility_of_element_located((By.XPATH,"//input[#name='daterangepicker_start']"))).click()
2
3
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\wait.py in until(self, method, message)
69 while True:
70 try:
---> 71 value = method(self._driver)
72 if value:
73 return value
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\expected_conditions.py in __call__(self, driver)
126 def __call__(self, driver):
127 try:
--> 128 return _element_if_visible(_find_element(driver, self.locator))
129 except StaleElementReferenceException:
130 return False
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\expected_conditions.py in _find_element(driver, by)
413 raise e
414 except WebDriverException as e:
--> 415 raise e
416
417
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\support\expected_conditions.py in _find_element(driver, by)
409 if thrown."""
410 try:
--> 411 return driver.find_element(*by)
412 except NoSuchElementException as e:
413 raise e
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py in find_element(self, by, value)
976 return self.execute(Command.FIND_ELEMENT, {
977 'using': by,
--> 978 'value': value})['value']
979
980 def find_elements(self, by=By.ID, value=None):
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
319 response = self.command_executor.execute(driver_command, params)
320 if response:
--> 321 self.error_handler.check_response(response)
322 response['value'] = self._unwrap_value(
323 response.get('value', None))
~\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
240 alert_text = value['alert'].get('text')
241 raise exception_class(message, screen, stacktrace, alert_text)
--> 242 raise exception_class(message, screen, stacktrace)
243
244 def _value_or_default(self, obj, key, default):
WebDriverException: Message: chrome not reachable
(Session info: chrome=81.0.4044.92)
Can you please check if your chrome browser is compatible with your chrome browser?
Could be possible your chrome is autommatically updated and now your chrome browser is not compatible with chrome driver.
You can download chrome driver from here

JPype and JayDeBeAPI: AttributeError: 'property' object has no attribute 'isBeanAccessor'

I have built JPype (JPype1-0.5.5.4) along with JayDeBeAPI 0.1.4 in my attempt to connect to a database via JDBC. This is on RHEL. I can successfully connect using the driver,
TrgtCnn = jaydebeapi.connect('com.ibm.as400.access.AS400JDBCDriver',
['jdbc:as400://<mask>','<mask>','<mask>'],
'/app/as/lib/jdbc/jt400.jar')
but I get this traceback in JPype when I execute SQL:
TrgtCrs = TrgtCnn.cursor()
TrgtCrs.execute("SELECT * FROM WA6U999S")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-5d46ea8c382d> in <module>()
----> 1 TrgtCrs.execute("SELECT * FROM WA6U999S")
/app/as/opt/anaconda/lib/python2.7/site-packages/jaydebeapi/dbapi2.pyc in execute(self, operation, parameters)
356 parameters = ()
357 self._close_last()
--> 358 self._prep = self._connection.jconn.prepareStatement(operation)
359 self._set_stmt_parms(self._prep, parameters)
360 is_rs = self._prep.execute()
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in _getClassFor(javaClass)
66 return _CLASSES[name]
67
---> 68 pyJavaClass = _JavaClass(javaClass)
69 _CLASSES[name] = pyJavaClass
70 return pyJavaClass
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in __new__(mcs, jc)
123 elif not jc.isInterface():
124 bjc = jc.getBaseClass(jc)
--> 125 bases.append(_getClassFor(bjc))
126
127 if _JAVATHROWABLE is not None and jc.isSubclass("java.lang.Throwable"):
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in _getClassFor(javaClass)
66 return _CLASSES[name]
67
---> 68 pyJavaClass = _JavaClass(javaClass)
69 _CLASSES[name] = pyJavaClass
70 return pyJavaClass
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_jclass.pyc in __new__(mcs, jc)
166 for i in _CUSTOMIZERS:
167 if i.canCustomize(name, jc):
--> 168 i.customize(name, jc, bases, members)
169
170 # remove multiple bases that would cause a MRO problem
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_properties.pyc in customize(self, class_name, jc, bases, members)
68
69 def customize(self, class_name, jc, bases, members) :
---> 70 accessor_pairs = _extract_accessor_pairs(members)
71 for attr_name, (getter, setter) in accessor_pairs.items():
72 if attr_name in members:
/app/as/opt/anaconda/lib/python2.7/site-packages/JPype1-0.5.5.4-py2.7-linux-x86_64.egg/jpype/_properties.pyc in _extract_accessor_pairs(members)
46 if _is_java_method(members[property_name]):
47 continue
---> 48 if access == 'get' and member.isBeanAccessor():
49 try:
50 pair = accessor_pairs[property_name]
AttributeError: 'property' object has no attribute 'isBeanAccessor'
I have no idea where to start on this and can't seem to find anything mentioning anything close to this issue.
This appears to be a bug in JPype.
I don't have access to an AS/400 database, but I do have an Oracle XE database lying around and I was able to use that to reproduce the problem. The Python code I used was as follows:
#!/usr/bin/python
import jaydebeapi
conn = jaydebeapi.connect('oracle.jdbc.OracleDriver', ['jdbc:oracle:thin:#localhost:1521:XE', 'user', 'password'])
print conn
I found what I believe to be a fix for the problem, which I have posted to the JPype issue above. This fix was to edit the function _extract_accessor_pairs in jpype/_properties.py, find the following code and replace the or with an and:
for name, member in members.items():
if not (len(name) > _PROPERTY_ACCESSOR_PREFIX_LEN \
or _is_java_method(member)):
continue
# rest of loop omitted...
After making this change, the error I was getting went away. You're welcome to try this fix and see if it works for you too.

Categories

Resources