proxy - 为什么远程机器人中的 ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) 会发生?
问题描述
我写了电报机器人并在美国地区的谷歌引擎上运行它(电报在我的国家被封锁)。大多数时候,一切正常,但有时机器人开始抛出错误
('连接中止。',ConnectionResetError(104,'连接被对等方重置'))
他两次给出这个错误(在两条消息上),第三次他回答得很好。在互联网上,这个问题的答案通常是代理问题。我不使用代理。有没有人遇到过类似的问题?有什么方法可以解决吗?
代码非常简单:
@bot.message_handler(commands=['check'])
def send_text(message):
try:
# Here bot connects to my db and gets info from it
bot.send_message(message.chat.id, 'some message')
except Exception as e:
print(e)
print("Problem in check function: ", message.chat.id)
if __name__ == '__main__':
while True:
try:
bot.polling(none_stop=True, timeout=30)
except:
time.sleep(15)
解决方案
由于与服务器的连接打开时间过长,因此引发了异常,因此它被拒绝。在您的机器人初始化中设置此参数以每 5 分钟重置一次连接:
apihelper.SESSION_TIME_TO_LIVE = 60 * 5
推荐阅读
- vespa - 没有会话 id,如何找到应用程序的内容 url。我只知道应用程序名称
- java - 在 RestTemplate 代码中得到 400 Request Bad Error 但在 SOAPUI 中得到正确的响应
- python - 如何将时间序列转换为从 00:00.00 开始的 %M:%S.%f
- java - MuteSetup 命令未设置有效的静音命令
- flutter - Dart @macro 在评论中
- node.js - Typegoose 类定义的静态方法返回空数组
- mysql - 是否有替代 ALTER TABLE AUTO_INCREMENT = 1 的方法?
- flutter - 颤振:为什么当textField失去焦点时输入内容消失?
- html - 如何使用 css 在 HTML 中制作内容
- spring-boot - zuul 2 带弹簧靴?