4

A general exception catcher logs the following exception:

Traceback (most recent call last):
  File "4sq.py", line 37, in <module>
    checkin = client.checkins()
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 416, in __call__
    return self.GET('{CHECKIN_ID}'.format(CHECKIN_ID=CHECKIN_ID), params, multi=multi)
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 217, in GET
    return self.requester.GET(self._expanded_path(path), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 163, in GET
    return self._request(url)
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 200, in _request
    return _request_with_retry(url, data)['response']
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 696, in _request_with_retry
    return _process_request_with_httplib2(url, data)
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 719, in _process_request_with_httplib2
    return _check_response(data)
  File "/usr/local/lib/python2.7/dist-packages/foursquare-20120716-py2.7.egg/foursquare/__init__.py", line 742, in _check_response
    raise exc(meta.get('errorDetail'))
RateLimitExceeded: Quota exceeded

I would like to know the specific exception name so I could add a dedicated catch to it. How can it be found?

Is there a 'type' function on the caught exception or should it be found in the throwing lib's source (available here)?

2
  • 6
    Looks like it's a RateLimitExceeded exception. Though, to be sure, I would wrap it in a try/except Exception as e and print e.__class__. That'll give you a definite answer Commented Nov 7, 2012 at 9:38
  • Thanks was looking for something like the e.__class__ ! Commented Nov 7, 2012 at 11:32

2 Answers 2

4

It looks like it's a RateLimitExceeded exception. Though, if you really want to be sure, you could do this:

try:
    # code
except Exception as e:
    print e.__class__

This would print out the exception class that was raised, which will give you a definitive answer

Sign up to request clarification or add additional context in comments.

Comments

1

The exception being raised in the paste is foursquare.RateLimitExceeded (as it says in the final line). You should be able to catch it as normal, or catch its base class foursquare.FoursquareException if you want to handle all errors from the module.

The code that raises the exception is just looking up which exception class to raise from a dictionary. That shouldn't have any effect on how you catch those errors.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.