This is a Discord app that I'm trying to make that takes in commands and reaches an api to give out a response. It works by itself but after being containerized it doesn't work at all. I'm trying to pass in an ENV commands to make it accept an API token so I don't have to hard code it in the container (it works when I do hard code it in the container though). I did a printenv in my container while running and it shows that the env variables are able to be printed. Any clues would definitely be appreciated.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 999, in _create_direct_connection
hosts = await asyncio.shield(host_resolved)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 865, in _resolve_host
addrs = await self._resolver.resolve(host, port, family=self._family)
File "/usr/local/lib/python3.10/site-packages/aiohttp/resolver.py", line 31, in resolve
infos = await self._loop.getaddrinfo(
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 860, in getaddrinfo
return await self.run_in_executor(
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/main.py", line 36, in <module>
bot.run(token)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 723, in run
return future.result()
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1011, in _create_direct_connection
raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discord.com:443 ssl:default [Temporary failure in name resolution]
main.py
import os
from discord.ext import commands
from call import *
token = os.environ['TOKEN']
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.command()
async def g(ctx, args):
await ctx.send(await g(args))
@bot.command()
async def descript(ctx, args):
await ctx.send(await desc(args))
@bot.command()
async def review(ctx, args):
await ctx.send("Metacritic Score: " + str(await metacritic(args)))
@bot.command()
async def image(ctx, args):
await ctx.send(await bg(args))
bot.run(token)
Dockerfile
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.10-slim
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "main.py"]