[Bug 2084973] [NEW] containers.exeute() fails on Python3.12+

Miha Purg 2084973 at bugs.launchpad.net
Sat Oct 19 12:42:30 UTC 2024


Public bug reported:

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) apt install python3-pylxd
4) 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

** Affects: python-pylxd (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
OpenStack, which is subscribed to python-pylxd in Ubuntu.
https://bugs.launchpad.net/bugs/2084973

Title:
  containers.exeute() fails on Python3.12+

Status in python-pylxd package in Ubuntu:
  New

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) apt install python3-pylxd
  4) 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-pylxd/+bug/2084973/+subscriptions




More information about the Ubuntu-openstack-bugs mailing list