diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index 6e09b193..22e1de67 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -500,6 +500,11 @@ class UploadMethods: if pos is not None: file.seek(pos) + if not isinstance(data, bytes): + raise TypeError( + 'file descriptor returned {}, not bytes (you must ' + 'open the file in bytes mode)'.format(type(data))) + file = data file_size = len(file) diff --git a/telethon/utils.py b/telethon/utils.py index b781e937..b2b1d89e 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -741,7 +741,7 @@ def _get_extension(file): elif isinstance(file, bytes): kind = imghdr.what(io.BytesIO(file)) return ('.' + kind) if kind else '' - elif isinstance(file, io.IOBase) and file.seekable(): + elif isinstance(file, io.IOBase) and not isinstance(file, io.TextIOBase) and file.seekable(): kind = imghdr.what(file) return ('.' + kind) if kind is not None else '' elif getattr(file, 'name', None):