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.

websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.

See original GitHub issue

Hi, I open the chrome browser and try to do anything after connecting to the dev tools, but anything I try results in ‘socket is already closed’…

Any suggestions?? (I have tried all of those lines and all of them end up throwing the socket closed error… chrome = PyChromeDevTools.ChromeInterface() - seems to be working fine.

subprocess.call(['open', '-a', "/Applications/Google Chrome.app", '--args', '--remote-debugging-port=9222'])
chrome = PyChromeDevTools.ChromeInterface()
chrome.Network.enable()
# chrome.Page.enable()
# chrome.Page.navigate(url="https://www.google.com")
# chrome.wait_event("Page.loadEventFired", timeout=60000)```

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Freakazocommented, Mar 12, 2019

@marty90 can you try and update so that websocket-client==0.55.0 which was release not too long ago to see if you can replicate the issue then?

I restricted the version to websocket-client==0.54.0 and the error others are getting above disappeared. @nba94 @mylh can youse force install that version of websocket-client to see if youse can still replicate the issue?

1reaction
code4dayscommented, Mar 9, 2019

I had the same issue, whats happening is that when you create a new instance without specifying a timeout chrome = PyChromeDevTools.ChromeInterface(), the timeout for the socket defaults to 1 second here, so basically the timeout you’re passing into wait_event is useless b/c message = self.ws.recv() times out within 1 second and raises an exception. To get around this specify a timeout when creating the ChromeInterface instance e.g. chrome = PyChromeDevTools.ChromeInterface(timeout=120), but now the timeout you pass into wait_event is only effective if its less than the socket timeout and there’s data coming in through the socket or else it will wait till the socket times out.

So the timeout in wait_event essentially means wait for the passed in event to show up in incoming messages until we hit the timeout, if no data is coming in the socket will timeout within a second, unless specified when you initialize ChromeInterface.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Web Socket closes immediately after opening
WebSocketConnectionClosedException : Connection is already closed. Any idea why its closing right away? Edit: Ran with enableTrace true. Here is ...
Read more >
WebSocket Error - Connection is already closed. - Qxf2 BLOG
I received this error when working on an application that involved a WebSocket connection. The Websocket handshake between the client and ...
Read more >
FAQ — websocket-client 1.4.2 documentation
The WebSocketConnectionClosedException, which returns the message “Connection is already closed.”, occurs when a WebSocket function such as send() ...
Read more >
Can't connect to websocket - Python Forum
I've spent some time now trying to connect to this websocket and I ... WebSocketConnectionClosedException: Connection is already closed.
Read more >
WebSocket API "Connection is already closed" - Forum
I am testing yours WebSocket API from the provided example market_price.py downloaded from this site. I get following response "Connection ...
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