From 3db13ccdd299349601afde6da22507a97ac7895a Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 25 Oct 2017 12:43:57 +0200 Subject: [PATCH] Add a more descriptive error when serializing bytes --- telethon/tl/tlobject.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/telethon/tl/tlobject.py b/telethon/tl/tlobject.py index 67a86300..1bd57878 100644 --- a/telethon/tl/tlobject.py +++ b/telethon/tl/tlobject.py @@ -93,8 +93,11 @@ class TLObject: @staticmethod def serialize_bytes(data): """Write bytes by using Telegram guidelines""" - if isinstance(data, str): - data = data.encode('utf-8') + if not isinstance(data, bytes): + if isinstance(data, str): + data = data.encode('utf-8') + else: + raise ValueError('bytes or str expected, not', type(data)) r = [] if len(data) < 254: