Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError - websockets.framing #133

Open
Camaendir opened this issue Jun 22, 2021 · 5 comments
Open

ModuleNotFoundError - websockets.framing #133

Camaendir opened this issue Jun 22, 2021 · 5 comments

Comments

@Camaendir
Copy link

Camaendir commented Jun 22, 2021

  • pySonoffLAN version: 0.3.0
  • Python version: 3.8.5 and 3.9.1
  • Operating System: Windows and WSL

Description

Trying to work with pysonofflan either through the given script or through the framework it throws the following ModuleNotFoundError.

File "python3.8/site-packages/pysonofflan/__init__.py", line 57, in <module> 
    from .client import SonoffLANModeClient
File "python3.8/site-packages/pysonofflan/client.py", line 11, in <module>   
    from websockets.framing import OP_CLOSE, parse_close, OP_PING, OP_PONG
ModuleNotFoundError: No module named 'websockets.framing

What I Did

either
from pysonofflan import * in python
or
python -m pysonofflan discover in bash/cmd

I already tried reinstalling/restarting everything.

@freebeans
Copy link

According to the websockets library changelog, websockets.framing is deprecated since version 9.0 which was released May 1st, 2021.

Maybe the author hasn't had the chance to fix it yet. Perhaps you can try installing an older version of the websockets library using virtualenv until it's fixed.

@beachhouse123
Copy link

beachhouse123 commented Jul 22, 2021

After further investigations I have made the following changes to get the application to run...

Websockets 9.1 has deprecated a number of unused API calls including some implemented in the websockets.framing module. The errors encountered when running with Websockets 9.1 can be cleared by commenting out imports in client.py
(/usr/local/lib/python3.9/site-packages/pysonofflan/client.py) line 11 as shown here:

import websockets
#from websockets.framing import OP_CLOSE, parse_close, OP_PING, OP_PONG

logger = logging.getLogger(__name__)

The problems identified in pysonofflan discover: too any open files #117 seem to be a ulimit problem which can be fixed by upping the ulimit e.g.

ulimit -n 10000

10000 is an arbitrary value, pick something appropriately large (default is 256)

With these changes in place pysonofflan appears to run but hangs performing some operations

2021-07-22 22:56:18,195 - info: Attempting to discover Sonoff LAN Mode devices on the local network, please wait...
2021-07-22 22:56:18,837 - info: Found Sonoff LAN Mode device at IP 192.168.0.10
2021-07-22 22:56:18,838 - info: Found Sonoff LAN Mode device at IP 192.168.0.28
$ pysonofflan --host 192.168.0.28 on
2021-07-22 22:56:25,283 - info: Initialising SonoffSwitch with host 192.168.0.28


I have this issue too using latest version of Websockets (9.1)

Python 3.9.6 running on Mac OSX 10.12.6

Marks-MBP:~ mark$ pysonofflan
Traceback (most recent call last):
File "/usr/local/bin/pysonofflan", line 5, in
from pysonofflan.cli import cli
File "/usr/local/lib/python3.9/site-packages/pysonofflan/init.py", line 57, in
from .client import SonoffLANModeClient
File "/usr/local/lib/python3.9/site-packages/pysonofflan/client.py", line 11, in
from websockets.framing import OP_CLOSE, parse_close, OP_PING, OP_PONG
ModuleNotFoundError: No module named 'websockets.framing'

Reverting to Websockets 8.1 does not work due to other issues.

@freebeans
Copy link

freebeans commented Jul 22, 2021

Interesting, but I don't think removing the imports from websockets.framing should be a fix. These aren't unused API calls, they are used inside of the SonoffLANModeClientProtocol class from client.py at line 77. Removing it might work for your use case, but might hurt some other functionality.

From the library's changelog, it doesn't seem they were unused by them either, they're just making them private instead of exporting them publicly. It means the functionality still exists but is implemented in a way that is inaccessible for this project.

Have you tried reverting to 8.1? Why did it not work? Have you tried virtualenv?
From the commits, issues and pull request's dates, this project seems to be unmaintained. It look like the correct fix for the issue could take some time to be released and perhaps reverting to the older version of the library is the best choice.

@beachhouse123
Copy link

beachhouse123 commented Jul 22, 2021

I removed the import from websockets.framing on the basis of the changelog for Websockets here:

https://websockets.readthedocs.io/en/stable/changelog.html#id2. The websockets.framing API have been deprecated-"The framing, handshake, headers, http, and uri modules in the websockets package are deprecated. These modules provided low-level APIs for reuse by other WebSocket implementations, but that never happened. Keeping these APIs public makes it more difficult to improve websockets for no actual benefit."

The terms that would be imported in client.py at line 11 are resolved in pyc files in /usr/local/lib/python3.9/site-packages/websockets/pycache

I have reverted all the way back to 6 with the same issue so I think the issue is likely to be a problem in my environment but I don't know why. I've compared my output with that expected and the resolution of IP address to device is not happening when pysonofflan hangs. In addition I now have some additional error messages after timeouts which give a clue:

pysonofflan discover
2021-07-23 00:36:06,742 - info: Attempting to discover Sonoff LAN Mode devices on the local network, please wait...
2021-07-23 00:36:07,388 - info: Found Sonoff LAN Mode device at IP 192.168.0.10
$ pysonofflan --host 192.168.0.10 listen
2021-07-23 00:36:27,815 - info: Initialising SonoffSwitch with host 192.168.0.10
2021-07-23 00:41:28,420 - error: SonoffLANModeClient connection failed: Malformed HTTP message
2021-07-23 00:41:28,421 - warning: Unable to connect: Malformed HTTP message


OK, this is my error. The Sonoff S26 device I am using is running r3.5.1 firmware which is incompatible with Pysonofflan. I don't have a device with V2 firmware on to test the above changes with.

@beveradb
Copy link
Owner

From the commits, issues and pull request's dates, this project seems to be unmaintained. It look like the correct fix for the issue could take some time to be released and perhaps reverting to the older version of the library is the best choice.

Hey, just wanted to say sorry for this, you're right in that I'm personally not doing any proactive efforts on this repo anymore as I don't actually have a sonoff with original firmware myself anymore (mine are all ESPHome or Tasmota now) so have no incentive to work on it.

However, if anyone wants to be given maintainer permissions I'm more than happy to grant that, or if anyone submits a PR which just needs to be merged/released I'm happy to do that if someone tags me specifically asking me to do that - as long as there's an understanding that I can't test it myself! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants