FlightAware Discussions

Any idea why the API would return a 401

I’ve double checked my key. Im using a version of the “Over Austin” tweet bot if that makes any difference ?

Also how many queries do I get for free (if any) as a feeder ? TIA

and here is the python… import traceback

import requests

def FlightInfo(ident, username, apiKey, verbose=0, results=10):
try:
fxmlUrl = “https://flightxml.flightaware.com/json/FlightXML3/
ident = ident.strip()
payload = {‘ident’:ident, ‘howMany’:results}
response = requests.get(fxmlUrl + “FlightInfoStatus”, params=payload, auth=(username, apiKey))
output = dict()
if response.status_code == 402:
print(response.text)
return False
if response.status_code == 200:
decodedResponse = response.json()
print(decodedResponse)
if ‘FlightInfoStatusResult’ not in decodedResponse:
return False
for flight in decodedResponse[‘FlightInfoStatusResult’][‘flights’]:
if ‘status’ not in flight:
continue
if flight[‘status’].startswith(‘On’) or flight[‘status’].startswith(‘En’) or flight[‘status’].startswith(‘In’):
output = {
“orig_name”:flight[‘origin’][‘airport_name’],
“orig_city”:flight[‘origin’][‘city’],
“orig_alt”:flight[‘origin’][‘alternate_ident’],
“orig_code”:flight[‘origin’][‘code’],
“dest_name”:flight[‘destination’][‘airport_name’],
“dest_city”:flight[‘destination’][‘city’],
“dest_alt”:flight[‘destination’][‘alternate_ident’],
“dest_code”:flight[‘destination’][‘code’]
}
break
if verbose:
return decodedResponse
else:
return output
else:
print(“FA API status code: {}”.format(response.status_code))
print(response.text)
return False
except Exception:
print(“exception in fa_api.FlightInfo():”)
traceback.print_exc()
return False

Your account only has a FlightXML 2 API key, but your code is attempting to access a FlightXML 3 (beta) method which requires a FlightXML 3 API key.

At this time we are no longer accepting new users to join the FlightXML 3 beta testing program, which is unfortunately the only way we were providing feeders with free limited access to our FlightXML APIs.