** Description changed:

  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)
-                 ^^^^^^^^^^^^^^^
+   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
+ 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')
+                       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

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

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-pylxd/+bug/2084973/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to