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

Using a remote api fails in python 3.12 #585

Open
gchamon opened this issue Jun 11, 2024 · 2 comments
Open

Using a remote api fails in python 3.12 #585

gchamon opened this issue Jun 11, 2024 · 2 comments

Comments

@gchamon
Copy link

gchamon commented Jun 11, 2024

The issue

Using python 3.12 and a remote client for lxd, I hit a problem with the ws4py package:

AttributeError                            Traceback (most recent call last)
Cell In[2], line 5
      3 client = pylxd.Client(endpoint="https://localhost:8443")
      4 instances = client.instances.all()
----> 5 instances[0].execute(["cat", "/etc/os-release"])

File ~/.local/share/virtualenvs/pylxd-yXHR9QOr/lib/python3.12/site-packages/pylxd/models/instance.py:475, in Instance.execute(self, commands, environment, encoding, decode, stdin_payload, stdin_encoding, stdout_handler, stderr_handler, user, group, cwd)
    469 stdin = _StdinWebsocket(
    470     self.client.websocket_url,
    471     payload=stdin_payload,
    472     encoding=stdin_encoding,
    473 )
    474 stdin.resource = f"{parsed.path}?secret={fds['0']}"
--> 475 stdin.connect()
    476 stdout = _CommandWebsocketClient(
    477     manager,
    478     self.client.websocket_url,
   (...)
    481     handler=stdout_handler,
    482 )
    483 stdout.resource = f"{parsed.path}?secret={fds['1']}"

File ~/.local/share/virtualenvs/pylxd-yXHR9QOr/lib/python3.12/site-packages/ws4py/client/__init__.py:214, in WebSocketBaseClient.connect(self)
    208 """
    209 Connects this websocket and starts the upgrade handshake
    210 with the remote endpoint.
    211 """
    212 if self.scheme == "wss":
    213     # default port is now 443; upgrade self.sender to send ssl
--> 214     self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
    215     self._is_secure = True
    217 self.sock.connect(self.bind_addr)

AttributeError: module 'ssl' has no attribute 'wrap_socket'

Steps to reproduce

First, make sure you are using python version 3.12, then add localhost to lxc remote, changing the password to mirror your local installation:

lxc remote add localhost --accept-certificate --password an-incredibly-secure-password

Spin up a virtual machine, then try to communicate using the endpoint:

import pylxd

client = pylxd.Client(endpoint="https://localhost:8443")
instances = client.instances.all()
instances[0].execute(["cat", "/etc/os-release"])

Possible solution

Given Lawouach/WebSocket-for-Python#283 the most likely boils down to updating ws4py dependency.

@mpurg
Copy link

mpurg commented Oct 21, 2024

I can confirm that this issue breaks important pylxd functionality (execute()) on a default installation of Ubuntu 24.04.1.

Linking also the to launchpad bug I opened before finding this issue:
https://bugs.launchpad.net/ubuntu/+source/python-pylxd/+bug/2084973

@simondeziel
Copy link
Member

As mentioned in the linked LP bug (which includes a nice reproducer, thanks @mpurg), there is nothing we can do about this in pyLXD as it's a problem in the dependent ws4py module.

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

3 participants