mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-17 21:56:07 -04:00
Handle new Tweepy exceptions properly. #403
This commit is contained in:
@@ -10,7 +10,7 @@ import output
|
||||
import application
|
||||
from pubsub import pub
|
||||
import tweepy
|
||||
from tweepy.errors import TweepyException
|
||||
from tweepy.errors import TweepyException, Forbidden, NotFound
|
||||
from tweepy.models import User as UserModel
|
||||
from mysc.thread_utils import call_threaded
|
||||
from keys import keyring
|
||||
@@ -200,13 +200,13 @@ class Session(base.baseSession):
|
||||
val = getattr(self.twitter, call_name)(*args, **kwargs)
|
||||
finished = True
|
||||
except TweepyException as e:
|
||||
output.speak(e.reason)
|
||||
output.speak(str(e))
|
||||
val = None
|
||||
if e.error_code != 403 and e.error_code != 404:
|
||||
if type(e) != NotFound and type(e) != Forvidden:
|
||||
tries = tries+1
|
||||
time.sleep(5)
|
||||
elif report_failure and hasattr(e, 'reason'):
|
||||
output.speak(_("%s failed. Reason: %s") % (action, e.reason))
|
||||
elif report_failure:
|
||||
output.speak(_("%s failed. Reason: %s") % (action, str(e)))
|
||||
finished = True
|
||||
# except:
|
||||
# tries = tries + 1
|
||||
@@ -422,7 +422,7 @@ class Session(base.baseSession):
|
||||
user.screen_name = "deleted_user"
|
||||
user.id = id
|
||||
user.name = _("Deleted account")
|
||||
if hasattr(err, "api_code") and err.api_code == 50:
|
||||
if type(err) == NotFound:
|
||||
self.deleted_users[id] = user
|
||||
return user
|
||||
else:
|
||||
@@ -490,7 +490,7 @@ class Session(base.baseSession):
|
||||
log.debug("Added %d new users" % (len(users)))
|
||||
self.db["users"] = users_db
|
||||
except TweepyException as err:
|
||||
if hasattr(err, "api_code") and err.api_code == 17: # Users not found.
|
||||
if type(err) == NotFound: # User not found.
|
||||
log.error("The specified users {} were not found in twitter.".format(user_ids))
|
||||
# Creates a deleted user object for every user_id not found here.
|
||||
# This will make TWBlue to not waste Twitter API calls when attempting to retrieve those users again.
|
||||
|
@@ -6,7 +6,7 @@ import logging
|
||||
import requests
|
||||
import time
|
||||
import sound
|
||||
from tweepy.errors import TweepyException
|
||||
from tweepy.errors import TweepyException, NotFound, Forbidden
|
||||
log = logging.getLogger("twitter.utils")
|
||||
""" Some utilities for the twitter interface."""
|
||||
|
||||
@@ -160,7 +160,7 @@ def if_user_exists(twitter, user):
|
||||
data = twitter.get_user(screen_name=user)
|
||||
return data
|
||||
except TweepyException as err:
|
||||
if err.api_code == 50:
|
||||
if type(err) == NotFound:
|
||||
return None
|
||||
else:
|
||||
return user
|
||||
@@ -227,12 +227,12 @@ def filter_tweet(tweet, tweet_data, settings, buffer_name):
|
||||
return True
|
||||
|
||||
def twitter_error(error):
|
||||
if error.api_code == 179:
|
||||
if type(error) == Forbidden:
|
||||
msg = _(u"Sorry, you are not authorised to see this status.")
|
||||
elif error.api_code == 144:
|
||||
elif type(error) == NotFound:
|
||||
msg = _(u"No status found with that ID")
|
||||
else:
|
||||
msg = _(u"Error code {0}").format(error.api_code,)
|
||||
msg = _(u"Error {0}").format(str(error),)
|
||||
output.speak(msg)
|
||||
|
||||
def expand_urls(text, entities):
|
||||
|
Reference in New Issue
Block a user