[Bug 2084973] Re: containers.execute() fails on Python3.12+
Miha Purg
2084973 at bugs.launchpad.net
Mon Oct 21 13:46:56 UTC 2024
Hi Simon, ok.
It was my initial plan to open it under ws4py but since the bug breaks pylxd functionality substantially, and is present on a default LTS installation and doesn't have a simple mitigation, I opened the bug there for better visibility.
** Bug watch added: github.com/canonical/pylxd/issues #585
https://github.com/canonical/pylxd/issues/585
--
You received this bug notification because you are a member of Ubuntu
OpenStack, which is subscribed to python-ws4py in Ubuntu.
https://bugs.launchpad.net/bugs/2084973
Title:
containers.execute() fails on Python3.12+
Status in python-ws4py package in Ubuntu:
Confirmed
Bug description:
When trying to execute a command on a container with pylxd (on Ubuntu
24.04.1 / Python 3.12.3), the following exception is raised:
```
Traceback (most recent call last):
File "/home/user/test.py", line 20, in <module>
instance.execute(['hostname'])
File "/usr/lib/python3/dist-packages/pylxd/models/container.py", line 412, in execute
stdin.connect()
File "/usr/lib/python3/dist-packages/ws4py/client/__init__.py", line 214, in connect
self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'
```
To reproduce:
1) snap install lxd
2) lxd init --auto
3) lxc config set core.https_address :8443
4) apt install python3-pylxd
5) Run below script
```
#!/usr/bin/env python3
import pylxd
import subprocess
subprocess.run("openssl req -x509 -newkey rsa:2048 -keyout lxd.key -nodes -out lxd.crt -subj '/CN=lxd.local'", shell=True)
lxd_token = subprocess.run("lxc config trust add --name test -q", capture_output=True, shell=True, text=True).stdout.strip()
# setup container
subprocess.run("lxc launch images:alpine/3.20 testc", shell=True)
client = pylxd.Client(endpoint='https://127.0.0.1:8443',
cert=('lxd.crt', 'lxd.key'),
verify='/var/snap/lxd/common/lxd/server.crt')
client.authenticate(lxd_token)
instance = client.containers.get('testc')
instance.execute(['hostname'])
```
The issue is with the `python3-ws4py` dependency calling `ssl.wrap_socket()`, which has been deprecated since 3.7 and removed in Python 3.12. Upstream has provided a patch, but not yet a release:
- https://github.com/Lawouach/WebSocket-for-Python/pull/283
- https://github.com/Lawouach/WebSocket-for-Python/issues/287
OS: Ubuntu 24.04.1
Python: 3.12.3
python3-pylxd: 2.2.10-3
python3-ws4py: 0.5.1+dfsg1-2
Thanks,
Miha
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-ws4py/+bug/2084973/+subscriptions
More information about the Ubuntu-openstack-bugs
mailing list