GithubHelp home page GithubHelp logo

Comments (8)

code4days avatar code4days commented on August 24, 2024 1

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.

from pychromedevtools.

Freakazo avatar Freakazo commented on August 24, 2024 1

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

from pychromedevtools.

tgianko avatar tgianko commented on August 24, 2024

I have the very same problem here. The exception originates here:

self.parent.ws.send(json.dumps(call_obj))

Somehow (for reasons), the websocket at that point is closed. It turns out that the line of code that does something (not sure what or why) is here:

self.parent.pop_messages()

Commenting out that line solves the issue. However, I do not know if this little change will break the time-space continuum.

(Update)
It turns out the exception is fired when a .recv() is done right after establishing a new connection and after a .settimeout(0). From that moment on, the websocket is unusable.

from pychromedevtools.

marty90 avatar marty90 commented on August 24, 2024

Guys I cannot reproduce the error. It is working fine on my Ubuntu and MacOS PCs. Do you have any special configuration of Chrome?

from pychromedevtools.

mylh avatar mylh commented on August 24, 2024

I have the same issue on only 1 server among ~20 the code runs at. Tried to specify timeout on ChromeInterface - didn't work. So this seems to be specific to server configuration. It is failing on linode instance, but works perfectly on digitalocean and vultr and on my local dev machines. All instances has equal CPU and RAM. The traceback is as follows:

chrome.Network.enable()
File "/home/webapps/local/lib/python2.7/site-packages/PyChromeDevTools/__init__.py", line 27, in generic_function
self.parent.ws.send(json.dumps(call_obj))
File "/home/webapps/local/lib/python2.7/site-packages/websocket/_core.py", line 253, in send
return self.send_frame(frame)
File "/home/webapps/local/lib/python2.7/site-packages/websocket/_core.py", line 278, in send_frame
l = self._send(data)
File "/home/webapps/local/lib/python2.7/site-packages/websocket/_core.py", line 448, in _send
return send(self.sock, data)
File "/home/webapps/local/lib/python2.7/site-packages/websocket/_socket.py", line 132, in send
raise WebSocketConnectionClosedException("socket is already closed.")
WebSocketConnectionClosedException: socket is already closed.

from pychromedevtools.

nba94 avatar nba94 commented on August 24, 2024

I have tried thechrome = PyChromeDevTools.ChromeInterface(timeout=120) suggestion but still does not work.
I am using the latest chrome version, nothing is custom.
Also I have tried the same thing on 2 different MacOS machines (Air and Pro) - the issue stands the same.

Below is the code I am trying to run:

import threading
import os
import subprocess
import PyChromeDevTools
import time

def open_chrome_supreme():
    subprocess.call(['open', '-a', "/Applications/Google Chrome.app", '--args', '--remote-debugging-port=9222'])

t = threading.Thread(target=open_chrome_supreme)
t.start()

time.sleep(10)

chrome = PyChromeDevTools.ChromeInterface(timeout=10000)
chrome.Page.navigate(url="https://www.google.com")
chrome.wait_event("Page.loadEventFired", timeout=60000)

And this is what I get when I try running it:

Traceback (most recent call last):
  File "test1.py", line 16, in <module>
    chrome.Page.navigate(url="https://www.google.com")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyChromeDevTools/__init__.py", line 27, in generic_function
    self.parent.ws.send(json.dumps(call_obj))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websocket/_core.py", line 253, in send
    return self.send_frame(frame)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websocket/_core.py", line 278, in send_frame
    l = self._send(data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websocket/_core.py", line 448, in _send
    return send(self.sock, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/websocket/_socket.py", line 132, in send
    raise WebSocketConnectionClosedException("socket is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.

from pychromedevtools.

nba94 avatar nba94 commented on August 24, 2024

@Freakazo I have force installed websocket-client==0.54.0 and it seems the issue is gone now! I will do some further testing in my main script and will update my comment.

@marty90 @mylh

from pychromedevtools.

mylh avatar mylh commented on August 24, 2024

Hi guys. I can confirm that installing websocket-client==0.54.0 has solved the issue for me. Thanks!

from pychromedevtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.