From 4fb410fdeb8f4a620bef94a60d6348c129cd16dd Mon Sep 17 00:00:00 2001 From: Edward Hades Date: Tue, 25 Jun 2013 20:19:33 +0200 Subject: [PATCH] wrap requests exceptions in TwythonError class --- twython/api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/twython/api.py b/twython/api.py index a133590..f4a7a0b 100644 --- a/twython/api.py +++ b/twython/api.py @@ -9,6 +9,8 @@ Twitter Authentication, and miscellaneous methods that are useful when dealing with the Twitter API """ +import sys + import requests from requests.auth import HTTPBasicAuth from requests_oauthlib import OAuth1, OAuth2 @@ -131,7 +133,10 @@ class Twython(EndpointsMixin, object): 'data': params, 'files': files, }) - response = func(url, **requests_args) + try: + response = func(url, **requests_args) + except requests.RequestException as e: + raise TwythonError, str(e), sys.exc_info()[2] content = response.content.decode('utf-8') # create stash for last function intel