I wrote a telegram bot on the aiogram framework. The bot worked fine for over a week, with no problems. The customer started complaining about the bot freezing. I downloaded the log file and saw a bunch of different TraceBacks. This situation has been happening for two days now. List of 3 TraceBacks, for example:
First
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # 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 "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 139, in make_request
async with session.post(url, data=req, **kwargs) as response:
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client.py", line 1138, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client.py", line 536, in _request
req, traces=traces, timeout=real_timeout
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 542, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 907, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 1187, in _create_direct_connection
client_error=client_error,
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Network is unreachable]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 385, in start_polling
allowed_updates=allowed_updates
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/bot.py", line 110, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/base.py", line 232, in request
proxy=self.proxy, proxy_auth=self.proxy_auth, timeout=self.timeout, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 142, in make_request
raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
aiogram.utils.exceptions.NetworkError: Aiohttp client throws an error: ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Network is unreachable]
Second
future: <Task finished coro=<Dispatcher._process_polling_updates() done, defined at /usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py:407> exception=TelegramAPIError('Gateway Timeout')>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/home/koval_pavlo03/TokenSaleBot/handlers/admin_commands.py", line 152, in do_adm
await message.answer_document(open('logs.txt', 'rb'))
File "/usr/local/lib/python3.7/dist-packages/aiogram/types/message.py", line 733, in answer_document
reply_markup=reply_markup,
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/bot.py", line 708, in send_document
result = await self.request(api.Methods.SEND_DOCUMENT, payload, files)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/base.py", line 232, in request
proxy=self.proxy, proxy_auth=self.proxy_auth, timeout=self.timeout, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 128, in check_result
raise exceptions.TelegramAPIError(description)
aiogram.utils.exceptions.TelegramAPIError: Gateway Timeout
Third
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 385, in start_polling
allowed_updates=allowed_updates
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/bot.py", line 110, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/base.py", line 232, in request
proxy=self.proxy, proxy_auth=self.proxy_auth, timeout=self.timeout, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 119, in check_result
exceptions.ConflictError.detect(description)
File "/usr/local/lib/python3.7/dist-packages/aiogram/utils/exceptions.py", line 140, in detect
raise err(cls.text or description)
aiogram.utils.exceptions.TerminatedByOtherGetUpdates: Terminated by other getupdates request; make sure that only one bot instance is running
01/21/2022 19:57:14 SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x7feef4858278>
transport: <_SelectorSocketTransport fd=9 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/usr/lib/python3.7/asyncio/sslproto.py", line 207, in feed_ssldata
self._sslobj.unwrap()
File "/usr/lib/python3.7/ssl.py", line 767, in unwrap
return self._sslobj.shutdown()
On my computer everything works fine. The bot is hosted on Google Cloud Platform (Compute engine). I have already tried restarting the bot and the host machine - it did not help; the problem appeared again today. I also changed the bot token, also did not work. For the sake of completeness, below is a list of versions:
$ python3 --version
Python 3.7.3
$ python3 -m pip show aiogram
Name: aiogram
Version: 2.18
Summary: Is a pretty simple and fully asynchronous framework for Telegram Bot API
Home-page: https://github.com/aiogram/aiogram
Author: Alex Root Junior
Author-email: jroot.junior#gmail.com
License: MIT
Location: /usr/local/lib/python3.7/dist-packages
Requires: aiohttp, Babel, certifi
Required-by:
$ python3 -m pip show aiohttp
Name: aiohttp
Version: 3.8.1
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: /usr/local/lib/python3.7/dist-packages
Requires: aiosignal, async-timeout, asynctest, attrs, charset-normalizer, frozenlist, multidict, typing-extensions, yarl
Required-by: aiogram
UPD
Here you can see log file (Google Drive)
The problem is that time on your host machine is different from world time.
I have noticed that Google Cloud compute engine doesn't have any time synchronization services. That explains why the bot works well for some time, and then he starts catching tracebacks.
Related
I am writing a telegram bot on the aiogram framework. Everything was good when I run it, but today I am getting error,Cannot connect to host api.telegram.org:443 ssl:default I do not know what's problem.
I am using Ubuntu 20.04.2 LTS
Here is the full error
Traceback (most recent call last):
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 1154, in _create_direct_connection
hosts = await asyncio.shield(host_resolved)
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 880, in _resolve_host
addrs = await self._resolver.resolve(host, port, family=self._family)
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/resolver.py", line 33, in resolve
infos = await self._loop.getaddrinfo(
File "/usr/lib/python3.8/asyncio/base_events.py", line 825, in getaddrinfo
return await self.run_in_executor(
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/socket.py", line 918, 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 "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/api.py", line 139, in make_request
async with session.post(url, data=req, **kwargs) as response:
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/client.py", line 1138, in __aenter__
self._resp = await self._coro
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/client.py", line 535, in _request
conn = await self._connector.connect(
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 542, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 907, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiohttp/connector.py", line 1166, in _create_direct_connection
raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Temporary failure in name resolution]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "app.py", line 18, in <module>
executor.start_polling(dp, on_startup=on_startup)
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 45, in start_polling
executor.start_polling(
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 320, in start_polling
loop.run_until_complete(self._startup_polling())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 372, in _startup_polling
await self._welcome()
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/utils/executor.py", line 361, in _welcome
user = await self.dispatcher.bot.me
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/bot.py", line 30, in me
setattr(self, '_me', await self.get_me())
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/bot.py", line 228, in get_me
result = await self.request(api.Methods.GET_ME, payload)
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/base.py", line 231, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "/home/mirodil/.local/share/virtualenvs/allinone-kbyzCwMv/lib/python3.8/site-packages/aiogram/bot/api.py", line 142, in make_request
raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
aiogram.utils.exceptions.NetworkError: Aiohttp client throws an error: ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Temporary failure in name resolution]
Your base url should be https://api.telegram.org/, with that being said it is common to see ConnectionError and ReadTimeout during polling.
But, looking at the error socket.gaierror: [Errno -3] Temporary failure in name resolution there is an issue in getting the address info for the host. I'd start with ruling out any connection issues and then check your /etc/hosts file to see if there are any misconfigurations.
If neither works, try polling the API directly to see if the problem still exists.
FYI: Here is how I'm polling the API directly without any framework and never had a problem.
https://github.com/thevickypedia/Jarvis/blob/master/modules/telegram/bot.py
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]
I have a shell script that runs Python scripts and the shell script is run by a crontab upon startup. I had the shell script log the error into a logs file each time it is run. When run manually the Python scripts run fine and there are no errors, the Python scripts run Discord bots btw. However when I reboot my Raspberry Pi, and leave the crontab to run the shell script, I receive in error which is below:
For context, there are 3 Python scripts, each one is named "main.py" in there respective folders. Here's the shell script if you want to look at it:
#!/bin/bash
cd /home/pi/Desktop/logs
DATE="$(date "+%m%d%Y_%T")"
touch "log_file_$DATE"
LOGFILE=/home/pi/Desktop/logs/log_file_$DATE
(
echo "-------------$(date "+%m/%d/%Y %T") : Starting work----------------"
cd "/home/pi/Desktop/InviteBot-master/"
/home/pi/Python-3.8.5/python main.py &
cd "/home/pi/Desktop/CustomRoleBot-master"
/home/pi/Python-3.8.5/python main.py &
cd "/home/pi/Desktop/Private-channel-manager-master"
/home/pi/Python-3.8.5/python main.py &
) >& $LOGFILE
sleep 86400
echo "-------------$(date "+%m/%d/%Y %T") : Restarting----------------"
sudo reboot
and here's the full log output (I replaced the bot token with asterisks for the purpose of presenting it)
-------------11/04/2020 16:53:36 : Starting work----------------
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 964, in _create_direct_connection
hosts = await asyncio.shield(self._resolve_host(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 829, in _resolve_host
addrs = await \
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/resolver.py", line 29, in resolve
infos = await self._loop.getaddrinfo(
File "/home/pi/Python-3.8.5/Lib/asyncio/base_events.py", line 825, in getaddrinfo
return await self.run_in_executor(
File "/home/pi/Python-3.8.5/Lib/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pi/Python-3.8.5/Lib/socket.py", line 918, 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 "main.py", line 338, in <module>
client.run(TOKEN)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 678, in run
return future.result()
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 658, in runner
await self.start(*args, **kwargs)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 621, in start
await self.login(*args, bot=bot)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 472, in login
await self.http.static_login(token.strip(), bot=bot)
File "/home/pi/.local/lib/python3.8/site-packages/discord/http.py", line 288, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/home/pi/.local/lib/python3.8/site-packages/discord/http.py", line 185, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/client.py", line 1012, in __aenter__
self._resp = await self._coro
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/client.py", line 480, in _request
conn = await self._connector.connect(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 858, in _create_connection
_, proto = await self._create_direct_connection(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 971, 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]
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 964, in _create_direct_connection
hosts = await asyncio.shield(self._resolve_host(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 829, in _resolve_host
addrs = await \
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/resolver.py", line 29, in resolve
infos = await self._loop.getaddrinfo(
File "/home/pi/Python-3.8.5/Lib/asyncio/base_events.py", line 825, in getaddrinfo
return await self.run_in_executor(
File "/home/pi/Python-3.8.5/Lib/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pi/Python-3.8.5/Lib/socket.py", line 918, 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 "main.py", line 215, in <module>
client.run(TOKEN)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 678, in run
return future.result()
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 658, in runner
await self.start(*args, **kwargs)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 621, in start
await self.login(*args, bot=bot)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 472, in login
await self.http.static_login(token.strip(), bot=bot)
File "/home/pi/.local/lib/python3.8/site-packages/discord/http.py", line 288, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/home/pi/.local/lib/python3.8/site-packages/discord/http.py", line 185, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/client.py", line 1012, in __aenter__
self._resp = await self._coro
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/client.py", line 480, in _request
conn = await self._connector.connect(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 858, in _create_connection
_, proto = await self._create_direct_connection(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 971, 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]
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 964, in _create_direct_connection
hosts = await asyncio.shield(self._resolve_host(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 829, in _resolve_host
addrs = await \
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/resolver.py", line 29, in resolve
infos = await self._loop.getaddrinfo(
File "/home/pi/Python-3.8.5/Lib/asyncio/base_events.py", line 825, in getaddrinfo
return await self.run_in_executor(
File "/home/pi/Python-3.8.5/Lib/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pi/Python-3.8.5/Lib/socket.py", line 918, 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 "main.py", line 1134, in <module>
client.run('*****')
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 678, in run
return future.result()
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 658, in runner
await self.start(*args, **kwargs)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 621, in start
await self.login(*args, bot=bot)
File "/home/pi/.local/lib/python3.8/site-packages/discord/client.py", line 472, in login
await self.http.static_login(token.strip(), bot=bot)
File "/home/pi/.local/lib/python3.8/site-packages/discord/http.py", line 288, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/home/pi/.local/lib/python3.8/site-packages/discord/http.py", line 185, in request
async with self.__session.request(method, url, **kwargs) as r:
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/client.py", line 1012, in __aenter__
self._resp = await self._coro
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/client.py", line 480, in _request
conn = await self._connector.connect(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 858, in _create_connection
_, proto = await self._create_direct_connection(
File "/home/pi/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 971, 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]
Thank you in advance for any help I can receive with this problem.
I figured out that I was getting the error because my network was not yet up. So I changed my shell script by adding this line of code before I executed the python scripts:
while ! (ping -c 1 -W 1 1.2.3.4 | grep -q 'statistics'); do
echo "Waiting for 1.2.3.4 - network interface might be down..."
sleep 1
done
I got the suggestion from here: https://www.raspberrypi.org/forums/viewtopic.php?t=148716
and the code from here: Waiting for network link to be up before continuing in bash
So I am using Pycharm, installed the discord.py and asyncio libraries in project interpreter. And I basically followed this video on Youtube: https://www.youtube.com/watch?v=D-7zuNRjqhw&t=190s
I have also tried other approaches like using atom which didn't work because of the python 3.7 and asyncio error.
If anyone can tell me what's going on that would be great or any other way to make a python discord bot, I am open to ideas.
the code:
import discord
import asyncio
from discord.ext import commands
client = commands.Bot(command_prefix="!")
#client.event
async def on_ready():
print("hello")
#client.command(pass_context=True)
async def ping(str):
await client.say("pong")
client.run("NTU3MjU2MTc5NTQyMTMwNzA5.D3FpXQ.QpSaso3vStRTet1m8CT8GYAJMvM")
and if I ran this code then it will return these error messages.
/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/bin/python /Users/SoyMilkFrank/PycharmProjects/untitled13/main.py
Traceback (most recent call last):
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 601, in _create_direct_connection
local_addr=self._local_addr)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 809, in create_connection
sock, protocol_factory, ssl, server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 835, in _create_connection_transport
yield from waiter
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 505, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 201, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 304, in connect
yield from self._create_connection(req)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 578, in _create_connection
transport, proto = yield from self._create_direct_connection(req)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 624, in _create_direct_connection
(req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 1] Can not connect to discordapp.com:443 [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/main.py", line 15, in <module>
client.run("NTU3MjU2MTc5NTQyMTMwNzA5.D3FpXQ.QpSaso3vStRTet1m8CT8GYAJMvM")
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 519, in run
self.loop.run_until_complete(self.start(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 473, in run_until_complete
return future.result()
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 490, in start
yield from self.login(*args, **kwargs)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 416, in login
yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/client.py", line 346, in _login_1
data = yield from self.http.static_login(token, bot=is_bot)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/http.py", line 258, in static_login
data = yield from self.request(Route('GET', '/users/#me'))
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/discord/http.py", line 137, in request
r = yield from self.session.request(method, url, **kwargs)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/client.py", line 555, in __iter__
resp = yield from self._coro
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/client.py", line 198, in _request
conn = yield from self._connector.connect(req)
File "/Users/SoyMilkFrank/PycharmProjects/untitled13/venv/lib/python3.6/site-packages/aiohttp/connector.py", line 314, in connect
.format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 1] Cannot connect to host discordapp.com:443 ssl:True [Can not connect to discordapp.com:443 [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10f6805c0>
Process finished with exit code 1
First of all do you need:
#client.command(pass_context = True)
Just replace it with:
#client.command()
Next for the ping function:
async def ping(ctx):
await ctx.send("Pong!")
Hope this helps, if you need any extra help join the Discord API Discord server. Also make sure you have the latest version of discord.py using pip
Hi i can't start my bot discord
root#boot:~/mdrk/discord.py# python3.5 discordbot.py
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 601, in _create_direct_connection
local_addr=self._local_addr)
File "/usr/local/lib/python3.5/asyncio/base_events.py", line 695, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
yield from self.sock_connect(sock, address)
File "/usr/local/lib/python3.5/asyncio/futures.py", line 361, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/local/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/local/lib/python3.5/asyncio/selector_events.py", line 439, in _sock_connect_cb
raise OSError(err, 'Connect call failed %s' % (address,))
OSError: [Errno 113] Connect call failed ('104.16.59.5', 443)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 304, in connect
yield from self._create_connection(req)
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 578, in _create_connection
transport, proto = yield from self._create_direct_connection(req)
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 624, in _create_direct_connection
(req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 113] Can not connect to discordapp.com:443 [Connect call failed ('104.16.59.5', 443)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "discordbot.py", line 121, in <module>
client.run('token')
File "/root/mdrk/discord.py/discord/client.py", line 518, in run
self.loop.run_until_complete(self.start(*args, **kwargs))
File "/usr/local/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
return future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/local/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/root/mdrk/discord.py/discord/client.py", line 489, in start
yield from self.login(*args, **kwargs)
File "/root/mdrk/discord.py/discord/client.py", line 416, in login
yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
File "/root/mdrk/discord.py/discord/client.py", line 346, in _login_1
data = yield from self.http.static_login(token, bot=is_bot)
File "/root/mdrk/discord.py/discord/http.py", line 258, in static_login
data = yield from self.request(Route('GET', '/users/#me'))
File "/root/mdrk/discord.py/discord/http.py", line 137, in request
r = yield from self.session.request(method, url, **kwargs)
File "/usr/local/lib/python3.5/site-packages/aiohttp/client.py", line 555, in __iter__
resp = yield from self._coro
File "/usr/local/lib/python3.5/site-packages/aiohttp/client.py", line 198, in _request
conn = yield from self._connector.connect(req)
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 314, in connect
.format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 113] Cannot connect to host discordapp.com:443 ssl:True [Can not connect to discordapp.com:443 [Connect call failed ('104.16.59.5', 443)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f21a06dae48>
I need you help
This is an educational open source project with many sub-projects. The one I am studying currently is the 'crawler' project. It requires python 3.4+ and aiohttp 1.2+. My current setup is Windows 10, Python 3.6.1, and aiohttp 2.0.4.
Strangely, my tests do not run and it is related to aiohttp. Can anybody familiar with aiohttp tell me why?
Here is the output I get: