From c4c263a85ba691bb3eab8637e5ab7f52667c59e4 Mon Sep 17 00:00:00 2001 From: st7105 Date: Tue, 9 Jul 2019 16:40:05 +0700 Subject: [PATCH] Use flush() only if it exists (#1227) --- telethon/client/downloads.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/telethon/client/downloads.py b/telethon/client/downloads.py index 5f14ceab..67388e44 100644 --- a/telethon/client/downloads.py +++ b/telethon/client/downloads.py @@ -439,7 +439,10 @@ class DownloadMethods: if inspect.isawaitable(r): await r - f.flush() + # Not all IO objects have flush (see #1227) + if callable(getattr(f, 'flush', None)): + f.flush() + if in_memory: return f.getvalue() finally: