python - 运行一段时间后 Telegram Bot 停止并给出错误
问题描述
user@instance-1:~$ sudo systemctl status telegrambot.service
● telegrambot.service - Telegram Bot
Loaded: loaded (/etc/systemd/system/telegrambot.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2020-05-16 07:43:49 UTC; 42min ago
Process: 40184 ExecStart=/home/user/telegrambot/venv/bin/python /home/user/telegrambot/bot.py (code=exited, status=1/FAILURE)
Main PID: 40184 (code=exited, status=1/FAILURE)
May 16 07:43:49 instance-1 python[40184]: result = _get_req_session().request(method, request_url, params=params, files=files,
May 16 07:43:49 instance-1 python[40184]: File "/home/user/telegrambot/venv/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
May 16 07:43:49 instance-1 python[40184]: resp = self.send(prep, **send_kwargs)
May 16 07:43:49 instance-1 python[40184]: File "/home/user/telegrambot/venv/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
May 16 07:43:49 instance-1 python[40184]: r = adapter.send(request, **kwargs)
May 16 07:43:49 instance-1 python[40184]: File "/home/user/telegrambot/venv/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
May 16 07:43:49 instance-1 python[40184]: raise ConnectionError(err, request=request)
May 16 07:43:49 instance-1 python[40184]: requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')"))
May 16 07:43:49 instance-1 systemd[1]: telegrambot.service: Main process exited, code=exited, status=1/FAILURE
May 16 07:43:49 instance-1 systemd[1]: telegrambot.service: Failed with result 'exit-code'.
有人可以帮我解决这个问题吗?在 Google Cloud Platform 上运行在 Ubuntu 上的服务器
解决方案
这对我有用
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
logger.error(e) # or just print(e) if you don't have logger,
# or import traceback; traceback.print_exc() for print full info
time.sleep(15)
推荐阅读
- android - Xamarin Android Style Xml 属性
- java - JPA在循环之前或之后不正确的合并
- r - 转换 data.frame 中除一个变量外的所有变量
- wordpress - 调用未定义的函数 settings_fields()
- scala - Scala Play:如何动态设置每种语言的响应视图?
- reactjs - 如何使 TextField 输入更宽?
- javascript - 更改图像的分辨率以匹配特定的像素密度 (DPI)
- python - 如何在一行中从数组中获取值(Python 3)
- swift - Paypal 从 Sandbox 切换到 Live - Swift SDK
- gml - 如何将瓦片图层转换为对象以进行相对于播放器的深度排序?