From 7582b4cce4bd617381475377ce6b1169f90b6261 Mon Sep 17 00:00:00 2001 From: Davte Date: Tue, 2 Jul 2019 14:43:58 +0200 Subject: [PATCH] Do not json-dump files --- davtelepot/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/davtelepot/api.py b/davtelepot/api.py index b0ccd0d..58de807 100644 --- a/davtelepot/api.py +++ b/davtelepot/api.py @@ -99,7 +99,10 @@ class TelegramBot(object): data = aiohttp.FormData() for key, value in parameters.items(): if not (key in exclude or value is None): - if type(value) in (int, dict, list,): + if ( + type(value) in (int, list,) + or (type(value) is dict and 'file' not in value) + ): value = json.dumps(value, separators=(',', ':')) data.add_field(key, value) return data @@ -206,7 +209,9 @@ class TelegramBot(object): certificate = self.certificate if type(certificate) is str: try: - certificate = open(certificate, 'r') + certificate = dict( + file=open(certificate, 'r') + ) except FileNotFoundError as e: logging.error(f"{e}\nCertificate set to `None`") certificate = None @@ -214,8 +219,8 @@ class TelegramBot(object): 'setWebhook', parameters=locals() ) - if certificate is not None: # Close certificate file, if it was open - certificate.close() + if type(certificate) is dict: # Close certificate file, if it was open + certificate['file'].close() return result async def deleteWebhook(self):