diff options
author | 2018-05-13 23:10:05 +0200 | |
---|---|---|
committer | 2018-05-13 23:10:05 +0200 | |
commit | 52242ecdad8e361e85aad132445b82a7e3987321 (patch) | |
tree | 4b59db0b26e73c0b125ae14fc5224c4b25f145bb | |
parent | Bump multidict from 4.2.0 to 4.3.1 (#71) (diff) |
Bugfix for the aiohttp bug with Network Unreachable - will force the session to use AF_INET on local sessions (#76)
-rw-r--r-- | bot/__main__.py | 14 | ||||
-rw-r--r-- | bot/constants.py | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/bot/__main__.py b/bot/__main__.py index 5c1184c10..0e2041bdb 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -1,11 +1,12 @@ import logging import os +import socket from aiohttp import AsyncResolver, ClientSession, TCPConnector from discord import Game from discord.ext.commands import AutoShardedBot, when_mentioned_or -from bot.constants import CLICKUP_KEY +from bot.constants import CLICKUP_KEY, DEBUG_MODE from bot.formatter import Formatter log = logging.getLogger(__name__) @@ -26,7 +27,16 @@ bot = AutoShardedBot( ) # Global aiohttp session for all cogs - uses asyncio for DNS resolution instead of threads, so we don't *spam threads* -bot.http_session = ClientSession(connector=TCPConnector(resolver=AsyncResolver())) +if DEBUG_MODE: + bot.http_session = ClientSession( + connector=TCPConnector( + resolver=AsyncResolver(), + family=socket.AF_INET, # Force aiohttp to use AF_INET if this is a local session. Prevents crashes. + verify_ssl=False, + ) + ) +else: + bot.http_session = ClientSession(connector=TCPConnector(resolver=AsyncResolver())) # Internal/debug bot.load_extension("bot.cogs.logging") diff --git a/bot/constants.py b/bot/constants.py index 4e8c9c900..651ffe0a8 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,5 +1,8 @@ import os +# Debug mode +DEBUG_MODE = True if 'local' in os.environ.get("SITE_URL", "local") else False + # Server PYTHON_GUILD = 267624335836053506 |