def __init__(self, credentials):
err_msg = ''
exception = None
self._logger = logging.getLogger(__name__)
try:
self._twitter_api = twitter.Api(
consumer_key=credentials['consumer_key'],
consumer_secret=credentials['consumer_secret'],
access_token_key=credentials['access_token_key'],
access_token_secret=credentials['access_token_secret']
)
except twitter.TwitterError as exc:
err_msg = 'The following error: %s, occurred while connecting ' \
'to the twitter API.' % exc.message
exception = exc
except KeyError as exc:
err_msg = 'Malformed credentials dictionary: %s.' % exc.message
exception = exc
except Exception as exc:
err_msg = 'An unhandled error: %s, occurred while connecting ' \
'to the twitter API.' % exc
exception = exc
if err_msg:
logging.getLogger(__name__).log(logging.ERROR, err_msg)
raise exception
评论列表
文章目录