문제

I have a small script that uses mechanize to go to a few websites to collect data. Sometimes the websites cause the script the crash and returns either "Bad Gateway" or "Connection Reset By Peer". I have an except line in the code so it emails me if there are any problems with the program, but I am trying to find a way to have it NOT email me in the case of these 2 problems. I've tried:

except Exception as e:
    if 'Gateway' not in e and 'peer' not in e:
        logger.error(e)

But this doesn't seem to work, as i still get emails if one of these 2 errors occur. What is the best way to have it email me in the case of any exception except for exceptions that contain certain text?

도움이 되었습니까?

해결책

Instead of e in your if statement, use str(e).

except Exception as e:
    if 'Gateway' not in str(e) and 'peer' not in str(e):
        logger.error(e)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top