question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python - "Connection refused" exception during wait and repeated script execution

See original GitHub issue

Meta -

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:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
begincalendarcommented, May 18, 2017

@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.

0reactions
deals4krcommented, Jan 11, 2018

Sure. Sorry for that, I am new user just joined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting the error "connection refused" in Python ...
This error means that for whatever reason the client cannot connect to the port on the computer running server script. This ...
Read more >
Troubleshooting | Apps Script - Google Developers
In this section we'll cover some techniques that can help you find, understand, and debug errors in your scripts.
Read more >
smtplib — SMTP protocol client — Python 3.11.1 documentation
The server refused our HELO message. The command or option attempted is not supported by the server.
Read more >
Common Errors and Solutions | CockroachDB Docs
connection refused. This message indicates a client is trying to connect to a node that is either not running or is not listening...
Read more >
Launch Experiments with wandb.init - Documentation
Call wandb.init() at the top of your script to start a new run. ... View the reference docs for this function, generated from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found