在由crontab运行时从Python套接字中获取错误,但在手动运行时不获取错误
我有一个运行Python脚本的shell脚本,shell脚本在启动时由crontab运行。我让shell脚本在每次运行时将错误记录到日志文件中。手动运行时,Python脚本运行良好且没有错误,Python脚本运行Discord bots顺便说一句。但是,当我重新启动Raspberry Pi并离开crontab运行shell脚本时,我收到以下错误消息: 对于上下文,有3个Python脚本,每个脚本在各自的文件夹中命名为“main.py”。下面是shell脚本,如果您想查看它:在由crontab运行时从Python套接字中获取错误,但在手动运行时不获取错误,python,shell,cron,Python,Shell,Cron,我有一个运行Python脚本的shell脚本,shell脚本在启动时由crontab运行。我让shell脚本在每次运行时将错误记录到日志文件中。手动运行时,Python脚本运行良好且没有错误,Python脚本运行Discord bots顺便说一句。但是,当我重新启动Raspberry Pi并离开crontab运行shell脚本时,我收到以下错误消息: 对于上下文,有3个Python脚本,每个脚本在各自的文件夹中命名为“main.py”。下面是shell脚本,如果您想查看它: #!/bin/bas
#!/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
这是完整的日志输出(为了显示它,我用星号替换了bot令牌)
-----------11/04/2020 16:53:36:开始工作----------------
回溯(最近一次呼叫最后一次):
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第964行,在创建直接连接中
hosts=wait asyncio.shield(self.\u resolve\u主机(
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第829行,在主机中
地址=等待\
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/resolver.py”,第29行,在resolve中
infos=等待自我。\u loop.getaddrinfo(
文件“/home/pi/Python-3.8.5/Lib/asyncio/base_events.py”,第825行,位于getaddrinfo中
返回等待自我运行执行器(
文件“/home/pi/Python-3.8.5/Lib/concurrent/futures/thread.py”,第57行,运行中
结果=self.fn(*self.args,**self.kwargs)
文件“/home/pi/Python-3.8.5/Lib/socket.py”,第918行,在getaddrinfo中
对于_socket.getaddrinfo(主机、端口、系列、类型、协议、标志)中的res:
socket.gaierror:[Errno-3]名称解析暂时失败
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“main.py”,第338行,在
client.run(令牌)
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第678行,正在运行
返回future.result()
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第658行,在runner中
等待自我启动(*args,**kwargs)
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第621行,在开始处
等待self.login(*args,bot=bot)
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第472行,登录
等待self.http.static\u登录(token.strip(),bot=bot)
静态登录中的文件“/home/pi/.local/lib/python3.8/site packages/discord/http.py”,第288行
data=wait self.request(路由('GET','/users/@me'))
文件“/home/pi/.local/lib/python3.8/site packages/discord/http.py”,第185行,在请求中
与self.\u session.request(方法、url、**kwargs)异步,作为r:
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/client.py”,第1012行,在__
self.\u resp=等待self.\u coro
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/client.py”,第480行,在请求中
conn=等待自检。\ U接头。连接(
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第523行,在connect中
proto=等待自我。创建连接(请求、跟踪、超时)
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第858行,在创建连接中
_,proto=等待自我。创建直接连接(
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第971行,在创建直接连接中
从exc引发客户端连接器错误(请求连接键,exc)
aiohttp.client_exceptions.clientconnector错误:无法连接到主机discord.com:443 ssl:default[名称解析暂时失败]
回溯(最近一次呼叫最后一次):
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第964行,在创建直接连接中
hosts=wait asyncio.shield(self.\u resolve\u主机(
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第829行,在主机中
地址=等待\
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/resolver.py”,第29行,在resolve中
infos=等待自我。\u loop.getaddrinfo(
文件“/home/pi/Python-3.8.5/Lib/asyncio/base_events.py”,第825行,位于getaddrinfo中
返回等待自我运行执行器(
文件“/home/pi/Python-3.8.5/Lib/concurrent/futures/thread.py”,第57行,运行中
结果=self.fn(*self.args,**self.kwargs)
文件“/home/pi/Python-3.8.5/Lib/socket.py”,第918行,在getaddrinfo中
对于_socket.getaddrinfo(主机、端口、系列、类型、协议、标志)中的res:
socket.gaierror:[Errno-3]名称解析暂时失败
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“main.py”,第215行,在
client.run(令牌)
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第678行,正在运行
返回future.result()
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第658行,在runner中
等待自我启动(*args,**kwargs)
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第621行,在开始处
等待self.login(*args,bot=bot)
文件“/home/pi/.local/lib/python3.8/site packages/discord/client.py”,第472行,登录
等待self.http.static\u登录(token.strip(),bot=bot)
静态登录中的文件“/home/pi/.local/lib/python3.8/site packages/discord/http.py”,第288行
data=wait self.request(路由('GET','/users/@me'))
文件“/home/pi/.local/lib/python3.8/site packages/discord/http.py”,第185行,在请求中
与self.\u session.request(方法、url、**kwargs)异步,作为r:
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/client.py”,第1012行,在__
self.\u resp=等待self.\u coro
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/client.py”,第480行,在请求中
conn=等待自检。\ U接头。连接(
文件“/home/pi/.local/lib/python3.8/site packages/aiohttp/connector.py”,第523行,在connect中
proto=等待自我。创建连接(请求、跟踪、超时)
F
-------------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]
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