3
votes

To sum up everything important:

I set up a raspberry py lite on an older raspberry pi model B.

I set a static ip over etc/dhcpcd.conf

I know that it has an internet connection since i downloaded pip3, and a few python modules after setting up the ip. (I use python3.7)

I wrote a small discord bot and tryed to execute the script from my desktop over PuTTY but when i try i get the following error message:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/lib/python3.7/asyncio/base_events.py", line 959, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.7/asyncio/base_events.py", line 946, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.7/asyncio/selector_events.py", line 464, in sock_connect
    return await fut
  File "/usr/lib/python3.7/asyncio/selector_events.py", line 469, in _sock_connect
    sock.connect(address)
OSError: [Errno 101] Network is unreachable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 25, in <module>
    bot.run(token)
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 723, in run
    return future.result()
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 665, in start
    await self.login(*args, bot=bot)
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "/home/pi/.local/lib/python3.7/site-packages/discord/http.py", line 300, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/home/pi/.local/lib/python3.7/site-packages/discord/http.py", line 192, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/client.py", line 521, in _request
    req, traces=traces, timeout=real_timeout
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/connector.py", line 1032, in _create_direct_connection
    client_error=client_error,
  File "/home/pi/.local/lib/python3.7/site-packages/aiohttp/connector.py", line 975, 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 [Network is unreachable]

By any chance does your bot start when you reboot your raspberry pi ? I also have that problem, my fix was to delay the script a bit before trying to run the botNathan Marotte
In a while True I bot.run(bot_token) in a try/except clause. If socket.gaierror is raised, I sleep 1 second, then it will try again, and on the else clause, i simply breakNathan Marotte
I allready rebooted a few times, i did once more but it didn't work. Thanks for the idea thoughDotchmoor
Did sadly not helpDotchmoor