From 6166d50580bc94b993b732ba42e8303b3af4cb4b Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Wed, 22 Aug 2018 16:34:34 +0200 Subject: [PATCH] Repair ftp timeout error --- main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index a6eef7b..a2a849b 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import ftplib import importlib import json import logging @@ -14,11 +15,12 @@ fileSystem = None if os.environ.get("FTP_ADDRESS", False) and os.environ.get("FTP_USER", False) and os.environ.get("FTP_PASS", False): print("FTP") - fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"]) + fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"], timeout=600) else: print("OS") fileSystem = OSFS(os.getcwd()) + # json decoder for int keys class Decoder(json.JSONDecoder): def decode(self, s, **kwargs): @@ -206,8 +208,13 @@ class FoBot(discord.Client): info("foBot is resumed.") async def on_error(self, event, *args, **kwargs): + if sys.exc_type == ftplib.error_temp: + global fileSystem + fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"], + timeout=600) error("foBot encounter an error.", exc_info=True) + async def on_message(self, msg): await self.guilds_class[msg.guild.id].on_message(msg)