Python Forum

Full Version: Error in the asyncio plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was making an AI bot for discord, everything is correct in the script, no errors, but the console finds errors in the asyncio plugin. I was running scripts in pythonanywhere. Python version: 3.10
Here are the errors:
Error:
Traceback (most recent call last): File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1025, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection raise exceptions[0] File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect return await fut File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('162.159.135.232', 443) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/Maden4ik/bot/GeminiSimple.py", line 184, in <module> bot.run(DISCORD_BOT_TOKEN) File "/home/Maden4ik/.local/lib/python3.10/site-packages/discord/client.py", line 869, in run asyncio.run(runner()) File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete return future.result() File "/home/Maden4ik/.local/lib/python3.10/site-packages/discord/client.py", line 858, in runner await self.start(token, reconnect=reconnect) File "/home/Maden4ik/.local/lib/python3.10/site-packages/discord/client.py", line 786, in start await self.login(token) File "/home/Maden4ik/.local/lib/python3.10/site-packages/discord/client.py", line 620, in login data = await self.http.static_login(token) File "/home/Maden4ik/.local/lib/python3.10/site-packages/discord/http.py", line 816, in static_login data = await self.request(Route('GET', '/users/@me')) File "/home/Maden4ik/.local/lib/python3.10/site-packages/discord/http.py", line 638, in request async with self.__session.request(method, url, **kwargs) as response: File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/client.py", line 1197, in __aenter__ self._resp = await self._coro File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/client.py", line 581, in _request conn = await self._connector.connect( File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 544, in connect proto = await self._create_connection(req, traces, timeout) File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 944, in _create_connection _, proto = await self._create_direct_connection(req, traces, timeout) File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1257, in _create_direct_connection raise last_exc File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1226, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "/home/Maden4ik/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1033, in _wrap_create_connection raise client_error(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discord.com:443 ssl:default [Connect call failed ('162.159.135.232', 443)]
What should I do?
I'm not sure where Pythonanywhere executes the code.
If the code is executed on a server of the provider, then it's normal that outgoing network connections aren't allowed because of abuse.
If the code is executed locally inside the browser, then it's a security feature, that it's not allowed to connect to a socket.
In other words, there is not an error in asyncio. Your program tried to do something that raised an exception. You need to find out why your AI bot was prevented from connecting to discord.com. I would start by googling aiohttp.client_exceptions.ClientConnectorError.