Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix UnicodeDecodeError (#1253)

fuenfundachtzigdbb4cafa451b
diff --git a/marimo/_server/files/os_file_system.py b/marimo/_server/files/os_file_system.py
index 3a92a49bad..67c311a044 100644
--- a/marimo/_server/files/os_file_system.py
+++ b/marimo/_server/files/os_file_system.py
@@ -92,8 +92,8 @@ class OSFileSystem(FileSystem):
if not path.endswith(".py"):
return False
- with open(path, "r") as file:
- return "app = marimo.App(" in file.read()
+ with open(path, "rb") as file:
+ return b"app = marimo.App(" in file.read()
def open_file(self, path: str, encoding: str | None = None) -> str:
try:
diff --git a/tests/_server/files/test_os_file_system.py b/tests/_server/files/test_os_file_system.py
index 9e1502f6df..76e38e41c9 100644
--- a/tests/_server/files/test_os_file_system.py
+++ b/tests/_server/files/test_os_file_system.py
@@ -100,6 +100,7 @@ class TestOSFileSystem(unittest.TestCase):
return mo,
if __name__ == "__main__":
+ # mäin
app.run()
"""
self.fs.create_file_or_directory(
@@ -110,6 +111,29 @@ class TestOSFileSystem(unittest.TestCase):
assert isinstance(file_info, FileDetailsResponse)
assert file_info.file.is_marimo_file
+ def test_get_details_marimo_file_nonutf(self) -> None:
+ test_file_name = "app.py"
+ content = """
+ import marimo
+ app = marimo.App()
+
+ @app.cell
+ def __():
+ import marimo as mo
+ return mo,
+
+ if __name__ == "__main__":
+ # mäin
+ app.run()
+ """
+ self.fs.create_file_or_directory(
+ self.test_dir, "file", test_file_name, content.encode("iso-8859-1")
+ )
+ file_path = os.path.join(self.test_dir, test_file_name)
+ file_info = self.fs.get_details(file_path)
+ assert isinstance(file_info, FileDetailsResponse)
+ assert file_info.file.is_marimo_file
+
def test_open_file(self) -> None:
test_file_name = "test_file.txt"
test_content = "Hello, World!"