如何处理计划脚本的套接字错误

时间:2018-06-29 06:40:34

标签: python linux

我有使用python Schedule模块的Schedule python脚本,在此脚本中,我每1小时查询一下ElasticSearch DB并在邮件上发送警报。但是,当我收到套接字错误时,调度脚本会自行终止。

NameError: name 'SocketError' is not defined
       try:
        with requests.Session() as s:
            time.sleep(.300)
            response = s.post(url, data=data, timeout=40)
        results = json.loads(response.text)
        return results
       except SocketError as e:
        if e.errno != errno.ECONNRESET:
            raise # Not error we are looking for
        print("Need to handle the error.")
        pass # Handle error here.

0 个答案:

没有答案