Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions meetup/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,11 @@ def _call(self, service_name, parameters=None, **kwargs):
self.rate_limit.limit,
self.rate_limit.reset))

if response.status_code == 401:
raise exceptions.HttpUnauthorized
if response.status_code == 404:
raise exceptions.HttpNotFoundError
if response.status_code == 410:
raise exceptions.HttpNotAccessibleError
# We handle 429 (Too Many Requests) errors down below by sleeping for the cool down time, then trying again.
# Raise an exception for any other 4xx or 5xx errors here
# TODO: Optimize this logic
if response.status_code != requests.codes.too_many_requests:
response.raise_for_status()

# If we have two or less remaining calls in the period, wait (if the wait flag is set).
# I tried only waiting after a 429 error, and ended getting locked out doing parallel testing.
Expand All @@ -194,7 +193,7 @@ def _call(self, service_name, parameters=None, **kwargs):
logger.warning('Approaching the rate limit. Sleeping for {0} seconds'.format(sleep_time))
sleep(sleep_time)

if response.status_code == 429:
if response.status_code == requests.codes.too_many_requests:
logger.error('Request limit exceeded.')
if self.overlimit_wait:
# We should have already waited
Expand Down
4 changes: 3 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pytest
from requests import HTTPError

from meetup import exceptions
from meetup.api import API_KEY_ENV_NAME, Client, MeetupObject
Expand All @@ -25,8 +26,9 @@ def test_empty_key(self, api_client):
def test_invalid_key(self, api_client):
# Same with invalid API Key
api_client.api_key = 'foobarbaz'
with pytest.raises(exceptions.HttpUnauthorized):
with pytest.raises(HTTPError) as excinfo:
api_client.GetDashboard()
assert '401 Client Error' in str(excinfo.value)


@pytest.mark.incremental
Expand Down
8 changes: 5 additions & 3 deletions tests/test_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from requests import HTTPError

from meetup import exceptions
from meetup.api import Client, MeetupObject


Expand All @@ -22,14 +22,16 @@ def test_get_valid_group(api_client, group_name):

@pytest.mark.parametrize("group_name", invalid_groups)
def test_get_invalid_group(api_client, group_name):
with pytest.raises(exceptions.HttpNotFoundError):
with pytest.raises(HTTPError) as excinfo:
api_client.GetGroup({'urlname': group_name})
assert '404 Client Error' in str(excinfo.value)


@pytest.mark.parametrize("group_name", inaccessible_groups)
def test_get_inaccessible_group(api_client, group_name):
with pytest.raises(exceptions.HttpNotAccessibleError):
with pytest.raises(HTTPError) as excinfo:
api_client.GetGroup({'urlname': group_name})
assert '410 Client Error' in str(excinfo.value)


@pytest.mark.parametrize("group_name", valid_groups)
Expand Down