From b89e73494d71b60104d259a38e50ddc18b929bba Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Fri, 13 Dec 2024 10:46:25 -0500 Subject: [PATCH] Tolerate IOBase objects without name attribute BytesIO/StringIO don't have this attribute unless explicitly assigned --- zxing/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zxing/__init__.py b/zxing/__init__.py index c95bcbe..ad1ad1f 100644 --- a/zxing/__init__.py +++ b/zxing/__init__.py @@ -85,7 +85,7 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod tf.flush() fn = tf.name elif isinstance(fn_or_im, IOBase): - tf = NamedTemporaryFile(prefix='temp_', suffix=os.path.splitext(fn_or_im.name)[1] or '.bin') + tf = NamedTemporaryFile(prefix='temp_', suffix=os.path.splitext(getattr(fn_or_im, 'name', ''))[1]) temp_files.append(tf) tf.write(fn_or_im.read()) tf.flush()