require_auth = True,
allowed_param = ['include_entities', 'skip_status'],
)(self, **kargs)
- except TweepError, e:
+ except TweepError as e:
if e.response and e.response.status == 401:
return False
raise
request.sign_request(self._sigmethod, self._consumer, None)
resp = urlopen(Request(url, headers=request.to_header()))
return oauth.OAuthToken.from_string(resp.read())
- except Exception, e:
+ except Exception as e:
raise TweepError(e)
def set_request_token(self, key, secret):
)
return request.to_url()
- except Exception, e:
+ except Exception as e:
raise TweepError(e)
def get_access_token(self, verifier=None):
resp = urlopen(Request(url, headers=request.to_header()))
self.access_token = oauth.OAuthToken.from_string(resp.read())
return self.access_token
- except Exception, e:
+ except Exception as e:
raise TweepError(e)
def get_xauth_access_token(self, username, password):
resp = urlopen(Request(url, data=request.to_postdata()))
self.access_token = oauth.OAuthToken.from_string(resp.read())
return self.access_token
- except Exception, e:
+ except Exception as e:
raise TweepError(e)
def get_username(self):
try:
conn.request(self.method, url, headers=self.headers, body=self.post_data)
resp = conn.getresponse()
- except Exception, e:
+ except Exception as e:
raise TweepError('Failed to send request: %s' % e)
# Exit request loop if non-retry error code
try:
zipper = gzip.GzipFile(fileobj=StringIO(body))
body = zipper.read()
- except Exception, e:
+ except Exception as e:
raise TweepError('Failed to decompress data: %s' % e)
result = self.api.parser.parse(self, body)
def parse(self, method, payload):
try:
json = self.json_lib.loads(payload)
- except Exception, e:
+ except Exception as e:
raise TweepError('Failed to parse JSON payload: %s' % e)
needsCursors = method.parameters.has_key('cursor')
self.snooze_time = self.snooze_time_step
self.listener.on_connect()
self._read_loop(resp)
- except (timeout, ssl.SSLError), exc:
+ except (timeout, ssl.SSLError) as exc:
# If it's not time out treat it like any other exception
if isinstance(exc, ssl.SSLError) and not (exc.args and 'timed out' in str(exc.args[0])):
exception = exc
sleep(self.snooze_time)
self.snooze_time = min(self.snooze_time + self.snooze_time_step,
self.snooze_time_cap)
- except Exception, exception:
+ except Exception as exception:
# any other exception is fatal, so kill loop
break
try:
from django.utils import simplejson as json # Google App Engine
except ImportError:
- raise ImportError, "Can't load a json library"
+ raise ImportError("Can't load a json library")
return json