[Python] Schiphol flight api, get flight information with python gets error

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to get data from a public api from schiphol (airport in Amsterdam). Im getting this api from https://api.schiphol.nl/public-flights/flights.

    I'm using python to get the flight data. In my code I get the error that the "app_id" is none while this is filled in....

    the full error from the console: Usage: flight_info_api.py [options]

    flight_info_api.py: error: Please provide an app id (-i, --app_id)

    Can anybody see what is going wrong?

    My code:

    import requests
    import sys
    import optparse


    def callPublicFlightAPI(options):
    url = 'https://api.schiphol.nl/public-flights/flights'

    headers = {
    'resourceversion': 'v4',
    'app_id': 'b209eb7f',
    'app_key': '0b6c58b5ae4595dd39785b55f438fc70'
    }

    try:
    response = requests.request('GET', url, headers=headers)
    except requests.exceptions.ConnectionError as error:
    print(error)
    sys.exit()

    if response.status_code == 200:
    flightList = response.json()
    print('found {} flights.'.format(len(flightList['flights'])))
    for flight in flightList['flights']:
    print('Found flight with name: {} scheduled on: {} at {}'.format(flight['flightName'],
    flight['scheduleDate'],
    flight['scheduleTime']))
    else:
    print('''Oops something went wrong Http response code: {}{}'''.format(response.status_code, response.text))


    if __name__ == '__main__':
    parser = optparse.OptionParser()
    parser.add_option('-i', '--app_id', dest='app_id',
    help='App id used to call the API')
    parser.add_option('-k', '--app_key', dest='app_key',
    help='App key used to call the API')

    (options, args) = parser.parse_args()
    if options.app_id is None:
    parser.error('Please provide an app id (-i, --app_id)')

    if options.app_key is None:
    parser.error('Please provide an app key (-key, --app_key)')

    callPublicFlightAPI(options)

    Continue reading...

Compartilhe esta Página