Queer European MD passionate about IT
소스 검색

Close certificate file after setting webhook

Davte 5 년 전
부모
커밋
3e6fc8ba42
1개의 변경된 파일5개의 추가작업 그리고 5개의 파일을 삭제
  1. 5 5
      davtelepot/api.py

+ 5 - 5
davtelepot/api.py

@@ -208,15 +208,15 @@ class TelegramBot(object):
             try:
                 certificate = open(certificate, 'r')
             except FileNotFoundError as e:
-                logging.error(f"{e}")
+                logging.error(f"{e}\nCertificate set to `None`")
                 certificate = None
-        # certificate = dict(
-        #     file=certificate
-        # )
-        return await self.api_request(
+        result = await self.api_request(
             'setWebhook',
             parameters=locals()
         )
+        if certificate is not None:  # Close certificate file, if it was open
+            certificate.close()
+        return result
 
     async def deleteWebhook(self):
         """Remove webhook integration and switch back to getUpdate.