# FlightAware authentication - python

**URL:** <https://discussions.flightaware.com/t/flightaware-authentication-python/81501>\
**Category:** AeroAPI\
**Created:** [February 6, 2022, 12:44pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501 "2022-02-06T12:44:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shodgsonaus](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/shodgsonaus/32/93500_2.png) [@shodgsonaus](https://discussions.flightaware.com/u/shodgsonaus)\
**Post date:** [February 6, 2022, 12:44pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/1 "2022-02-06T12:44:06Z")

</div>

Hey gang,  
Im using Python to with my RPi and FlightAware. There are settings in the config to get additional flight data from FA, but Im getting the following debug message in my log file.

> FA API status code: 401
> 
> Authentication Required
> # Authentication Required

The following is in my config file, of which the API key is taken from my flightaware account, and my username is my name here.

> [flightaware]  
> ; FlightAware API allows to get more information on the flights. Basic API access is now free  
> ; and if you are FA feeder, your request limit is doubled. For more details check:  
> ; [https://flightaware.com/commercial/flightxml/pricing\_class.rvt](https://flightaware.com/commercial/flightxml/pricing_class.rvt)  
> fa\_enable = True  
> fa\_username = shodgsonaus  
> fa\_api\_key = \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Can anyone please kindly shed some light on why I might be getting authentication issues?

Many thanks…Simon

---

<div class="post-metadata">

**Author:** ![LawrenceHill](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/lawrencehill/32/113365_2.png) [@LawrenceHill](https://discussions.flightaware.com/u/LawrenceHill)\
**Post date:** [February 6, 2022, 1:18pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/2 "2022-02-06T13:18:24Z")

</div>

> [@shodgsonaus](#):
>
> Can anyone please kindly shed some light on why I might be getting authentication issues?

I take it you do have `fxmlUrl` Set to the correct value for FlightXML3 ?`https://flightxml.flightaware.com/json/FlightXML3/`  
I know that authentication issues arise if you call the wrong version to that associated with your account.  
See this discussion where someone had a similar problem:

> [@Python technical support](https://discussions.flightaware.com/t/python-technical-support/69971/6):
>
> The API key associated with your account is for FlightXML v2, but the fxmlURL in the example used is for FlightXML v3. This will cause the authentication to fail and the response status code to be a 401. If your example only prints a result on a status code 200 occurs then this is why there is no output. Please try changing the fxmlUrl the value to https://flightxml.flightaware.com/json/FlightXML2/ and update the request to match the format of one of the [FlightXML v2 requests found here](https://flightaware.com/commercial/flightxml/explorer/). You ma…

---

<div class="post-metadata">

**Author:** ![shodgsonaus](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/shodgsonaus/32/93500_2.png) [@shodgsonaus](https://discussions.flightaware.com/u/shodgsonaus)\
**Post date:** [February 6, 2022, 1:39pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/3 "2022-02-06T13:39:08Z")

</div>

@LawrenceHill  
To the rescue once more champion

I’ll look into that right now. Thankyou.

I’ll let you know if any success.

Thankyou again Sir.

---

<div class="post-metadata">

**Author:** ![shodgsonaus](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/shodgsonaus/32/93500_2.png) [@shodgsonaus](https://discussions.flightaware.com/u/shodgsonaus)\
**Post date:** [February 6, 2022, 3:04pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/4 "2022-02-06T15:04:21Z")

</div>

Unfortunately no success on that front Im afraid.  
Im trying to set the variable in my python code as follows:

> # Assign FlightAware variables.
> 
> fxmlUrl = ‘[https://flightxml.flightaware.com/json/FlightXML3/](https://flightxml.flightaware.com/json/FlightXML3/)’  
> fa\_enable = parser.getboolean(‘flightaware’, ‘fa\_enable’)  
> fa\_username = parser.get(‘flightaware’, ‘fa\_username’)  
> fa\_api\_key = parser.get(‘flightaware’, ‘fa\_api\_key’)

And this in my config.ini

> [flightaware]  
> ; FlightAware API allows to get more information on the flights. Basic API access is now free  
> ; and if you are FA feeder, your request limit is doubled. For more details check:  
> ; [https://flightaware.com/commercial/flightxml/pricing\_class.rvt](https://flightaware.com/commercial/flightxml/pricing_class.rvt)  
> fa\_enable = True  
> fa\_username = shodgsonaus  
> fa\_api\_key = xxxxxxxxxxxxxxxxxxxxxxxxx

Im sure Im missing something incredibly simple.

Cheers  
Simon

---

<div class="post-metadata">

**Author:** ![dogrock](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/dogrock/32/118974_2.png) [@dogrock](https://discussions.flightaware.com/u/dogrock)\
**Post date:** [February 7, 2022, 4:14pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/5 "2022-02-07T16:14:42Z")

</div>

Sorry for the confusion. All new AeroAPI users should be on version 4 now. This means that the old AeroAPI examples involving a FlightAware username as a part of the authentication or “flightxml” in the url are out of date and should not longer be referenced for new users.

The new api URL is `https://aeroapi.flightaware.com/aeroapi/` and and only the API Key is used for authentication in the request header `x-apikey`. The various resources can be seen in the [Documentation Portal](https://flightaware.com/aeroapi/portal/documentation). With a slight change to the apiKey line, the python snippet from the product page can be used to fetch the API key from your config.ini.

```auto
import requests

apiKey = parser.get(‘flightaware’, ‘fa_api_key’)
apiUrl = "https://aeroapi.flightaware.com/aeroapi/"

airport = 'KSFO'
payload = {'max_pages': 1}
auth_header = {'x-apikey':apiKey}

response = requests.get(apiUrl + f"airports/{airport}/flights",
    params=payload, headers=auth_header)

if response.status_code == 200:
    print(response.json())
else:
    print("Error executing request")

```

---

<div class="post-metadata">

**Author:** ![shodgsonaus](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/shodgsonaus/32/93500_2.png) [@shodgsonaus](https://discussions.flightaware.com/u/shodgsonaus)\
**Post date:** [February 5, 2022, 8:11pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/6 "2022-02-05T20:11:18Z")

</div>

Hey gang,  
Im using Python to with my RPi and FlightAware. There are settings in the config to get additional flight data from FA, but Im getting the following debug message in my log file.

> FA API status code: 401
> 
> Authentication Required
> # Authentication Required

The following is in my config file, of which the API key is taken from my flightaware account, and my username is my name here.

> [flightaware]  
> ; FlightAware API allows to get more information on the flights. Basic API access is now free  
> ; and if you are FA feeder, your request limit is doubled. For more details check:  
> ; [https://flightaware.com/commercial/flightxml/pricing\_class.rvt](https://flightaware.com/commercial/flightxml/pricing_class.rvt)  
> fa\_enable = True  
> fa\_username = shodgsonaus  
> fa\_api\_key = \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Can anyone please kindly shed some light on why I might be getting authentication issues?

Many thanks…Simon

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/system/32/38558_2.png) [@system](https://discussions.flightaware.com/u/system)\
**Post date:** [February 5, 2023, 8:11pm UTC](https://discussions.flightaware.com/t/flightaware-authentication-python/81501/7 "2023-02-05T20:11:45Z")

</div>

Closed on February 5, 2023, 8:11pm UTC

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
