From 97e107ce1477a2950a000819212b7d518827498e Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 6 Nov 2026 10:56:14 +0300 Subject: [PATCH] fix(instances): no deprecated crypt module from Python 3.11 The root password hash for a shut-off VM used crypt_r where installed (Python 3.13) and fell back to the stdlib crypt, which Python 3.11 and 3.12 deprecate: `python -W error::DeprecationWarning manage.py check` failed there. crypt-r (the same module, it requires Python 3.11) is now installed from 3.11, and the module is chosen by the Python version; 3.10's crypt is not deprecated. --- conf/requirements.txt | 2 +- instances/views.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/conf/requirements.txt b/conf/requirements.txt index 0dc21dbf..77152c96 100644 --- a/conf/requirements.txt +++ b/conf/requirements.txt @@ -23,4 +23,4 @@ python-socketio==5.18.1 segno==1.6.6 websockify==0.13.0 whitenoise==6.12.0 -crypt-r>=3.13.0; python_version >= "3.13" +crypt-r>=3.13.0; python_version >= "3.11" diff --git a/instances/views.py b/instances/views.py index 199401bf..f2f92a38 100755 --- a/instances/views.py +++ b/instances/views.py @@ -1,7 +1,3 @@ -try: - import crypt_r as crypt -except ImportError: - import crypt import difflib import functools import hashlib @@ -11,10 +7,17 @@ import os import re import secrets import socket +import sys import subprocess import time from ipaddress import ip_address +# the stdlib crypt is deprecated from Python 3.11 and gone in 3.13: crypt_r is the same module +if sys.version_info >= (3, 11): + import crypt_r as crypt +else: + import crypt + from accounts.models import UserInstance, UserSSHKey from admin.decorators import superuser_only from appsettings.models import AppSettings