I have a list of twitter usernames that I use to get tweets. During the process, I face 2 main errors:
CRITICAL:root:twint.get:User:'user'
raise ValueError("Cannot find twitter account with name = " + self.config.Username)
ValueError: Cannot find twitter account with name = blablabla
CRITICAL:root:twint.get:User:'data'
raise ValueError("Cannot find twitter account with name = " + self.config.Username)
ValueError: Cannot find twitter account with name = blablabla
The first one happens when the username is incorrect and I don't mind passing the error. However, the second one I believe is due to connection timeout or something similar, because whenever I get that error, I stop the script for 3-4 minutes and continue and it goes on as usual.
Therefore, I want to catch the 2nd error and handle it with sleep(). The problem is, if I do this it will sleep through incorrect username error as well and that's a waste of time:
try:
some code
except ValueError:
sleep(200)
How can I make it sleep only if the 2nd error happens?