Python - "Connection refused" exception during wait and repeated script execution
See original GitHub issueMeta -
OS: Ubuntu 16.04 x64
Selenium Version: 2.53.2 (Python 3)
Browser: Google Chome and Firefox
Browser Version: 46.0 and 50.0.2661.94
Expected Behavior -
No “[Errno 111] Connection refused” exception to be raised.
Actual Behavior -
“[Errno 111] Connection refused” exception is raised.
Steps to reproduce -
I can’t provide a small example because the issue doesn’t consistently occur, it’s quite sporadic.
The best I can provide is a stack trace:
File "my_client_code.py", line 21, in _record_id_present
'return !!$(".tab_window_form").attr("data-record_id")')
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 461, in execute_script
{'script': script, 'args':converted_args})['value']
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 231, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/remote_connection.py", line 425, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/usr/lib/python3.5/http/client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
[Errno 111] Connection refused
So I’m calling WebDriver.execute_script()
(checking if an element has a certain attribute value), from a WebDriverWait.until()
.
It affects both Chrome and Firefox, so I’m guessing that rules out issues with the web drivers and places the blame on Selenium, somehow.
If it helps, the issue usually arises when I max out of my CPU cores with parallel processes of differing client code (which all do the same wait condition, at various stages, multiple times).
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
@ratatatatat I was caching the wait objects in a poor way, such that when a browser X was closed and I thought I was waiting on browser Y (which would still be open), it would actually be waiting on browser X (whose socket is no longer open, hence the error).
Just make sure the browser your
driver
points to (at the time of that call), is still open.Otherwise it’s probably another issue.
Sure. Sorry for that, I am new user just joined.