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

Flights.get_results blows up if create_session gets "error" answer from SkyScanner server #24

Open
ditiem opened this issue Feb 22, 2017 · 0 comments

Comments

@ditiem
Copy link

ditiem commented Feb 22, 2017

The method create_session in the Flights class does not always return a "url" (see POINT 2 below, where a callback is supposed to be called to return the Location header for a given response object), making the call to "poll_session" (see POINT 1 below) blow up. Notice create_session returns a "request library" response object if something went wrong.

PROBLEM:

Notice poll_session calls make_request straight away passing poll_url without any check:

def poll_session(self, poll_url, initial_delay=2, delay=1, tries=20,
                 errors=GRACEFUL, **params):
    ...
    for n in range(tries):
        poll_response = **self.make_request(
            poll_url,**
            headers=self._headers(),
            errors=errors, **params
        )

and in make_request there is a line that assumes the first argument, service_url, is an string:

    if 'apikey' not in service_url.lower(): <--- Boom! Object Response does not have any lower method

TRACE:

class Transport(object):
...
    def get_result(self, errors=GRACEFUL, **params):
    ...
        return self.poll_session(
            self.create_session(**params), <--- POINT 1


class Flights(Transport):
    ...
    def create_session(self, **params):
        ...
        return self.make_request(self.PRICING_SESSION_URL,
                                 method='post',
                                 headers=self._session_headers(),
                                 allow_redirects=False,
                                 callback=lambda resp: resp.headers['location'],  <---- POINT 2
                                 data=params)

POINT 2 is not executed, and instead Flights.create_session returns a response object, which becomes the poll_url argument of poll_session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant