diff --git a/api/funkwhale_api/music/management/commands/import_files.py b/api/funkwhale_api/music/management/commands/import_files.py
index fab980510d77b045df80df803d0fa40642a520ac..ddc598d06fcf5dfa50ac1508c90e563c59cf6a0e 100644
--- a/api/funkwhale_api/music/management/commands/import_files.py
+++ b/api/funkwhale_api/music/management/commands/import_files.py
@@ -27,7 +27,8 @@ def crawl_dir(dir, extensions, recursive=True, ignored=[]):
     if os.path.isfile(dir):
         yield dir
         return
-    with os.scandir(dir) as scanner:
+    try:
+        scanner = os.scandir(dir)
         for entry in scanner:
             if entry.is_file():
                 for e in extensions:
@@ -38,6 +39,9 @@ def crawl_dir(dir, extensions, recursive=True, ignored=[]):
                 yield from crawl_dir(
                     entry, extensions, recursive=recursive, ignored=ignored
                 )
+    finally:
+        if hasattr(scanner, "close"):
+            scanner.close()
 
 
 def batch(iterable, n=1):
diff --git a/api/tests/files/nested/valid.ogg b/api/tests/files/nested/valid.ogg
new file mode 100644
index 0000000000000000000000000000000000000000..e1643848a07a548e55d53726d4e4fe168a8ab2cd
Binary files /dev/null and b/api/tests/files/nested/valid.ogg differ
diff --git a/api/tests/test_import_audio_file.py b/api/tests/test_import_audio_file.py
index 04c06a8f462fbdd7db3dfe4e31139f7edc5585c6..7ee1028c8fd7e331208474a7a871bd41931e1bb4 100644
--- a/api/tests/test_import_audio_file.py
+++ b/api/tests/test_import_audio_file.py
@@ -352,3 +352,17 @@ def test_handle_modified_update_existing_path_if_found_and_attributed_to(
         event=event, stdout=stdout, library=library, in_place=True,
     )
     update_track_metadata.assert_not_called()
+
+
+def test_import_files(factories, capsys):
+    # smoke test to ensure the command run properly
+    library = factories["music.Library"](actor__local=True)
+    call_command(
+        "import_files", str(library.uuid), DATA_DIR, interactive=False, recursive=True
+    )
+    captured = capsys.readouterr()
+
+    imported = library.uploads.filter(import_status="finished").count()
+    assert imported > 0
+    assert "Successfully imported {} new tracks".format(imported) in captured.out
+    assert "For details, please refer to import reference" in captured.out
diff --git a/changes/changelog.d/1048.bugfix b/changes/changelog.d/1048.bugfix
new file mode 100644
index 0000000000000000000000000000000000000000..0f1973444147ffad54d32a715f7fa5d9a07dda28
--- /dev/null
+++ b/changes/changelog.d/1048.bugfix
@@ -0,0 +1 @@
+Fixed recursive CLI importing crashing under Python 3.5 (#1148, #1147)