Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling for 304 not modified responses #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions skyscanner/skyscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class MissingParameter(KeyError):
"""Is thrown when expected request parameter is missing."""
pass

class NotModified(Exception):

"""Is thrown when the server gives a 304 response."""
pass

class Transport(object):

Expand Down Expand Up @@ -166,13 +170,17 @@ def poll_session(self, poll_url, initial_delay=2, delay=1, tries=20, errors=STRI
time.sleep(initial_delay)
poll_response = None
for n in range(tries):
poll_response = self.make_request(poll_url, headers=self._headers(),
errors=errors, **params)
try:
poll_response = self.make_request(poll_url, headers=self._headers(),
errors=errors, **params)

if self.is_poll_complete(poll_response):
return poll_response
else:
time.sleep(delay)
if self.is_poll_complete(poll_response):
return poll_response

except NotModified:
pass
time.sleep(delay)


if STRICT == errors:
raise ExceededRetries(
Expand Down Expand Up @@ -265,6 +273,9 @@ def _headers(self):
return {'Accept': 'application/%s' % self.response_format}

def _default_resp_callback(self, resp):
if resp and resp.status_code == 304:
raise NotModified

if not resp or not resp.content:
raise EmptyResponse('Response has no content.')

Expand Down