Encoding error sometimes returned from AirportInfo requests

I’m using the code below to request Airport information from the API and save it into delimited text files. Certain airports work fine and the data comes back as expected. However other airports return an error, which I think is something to do with text encoding.

This airport code works fine: 83Q
This airport code (plus many others) returns the error: AGGG

This is the error:

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0=“http://flightxml.flightaware.com/soap/FlightXML2” xmlns:ns1=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”>
SOAP-ENV:Header/
ns1:Body
ns0:AirportInfoRequest
ns0:airportCode’AGGG’</ns0:airportCode>
</ns0:AirportInfoRequest>
</ns1:Body>
</SOAP-ENV:Envelope>

This is the Python code I’m using to request the data:



#First import required libraries so that SOAP requests can be made and the date can be inserted:
import sys
from suds import null, WebFault
from suds.client import Client
import logging
from datetime import datetime

#Store login details and remote server URL in variables
username = 'myusername'
apiKey = 'myapiKey123'
url = 'http://flightxml.flightaware.com/soap/FlightXML2/wsdl'
logging.basicConfig(level=logging.INFO)
api = Client(url, username=username, password=apiKey)


# Get the airport info and record any errors returned by API:
ResultList = ]
ErrorList = ]
result = ]

try:
        result = api.service.AirportInfo("'" + 'AGGG' + "'")
except Exception as Err:
        ErrorList.append(str(datetime.now()) + "|" \
                         + 'AGGG' + '|' \
                         + str(Err) + "
")
else:
    ResultList.append('"' + 'AGGG' + '"' +"|" \
                      '"' + str(result'latitude']) + '"' +"|" \
                      '"' + str(result'location']) + '"' +"|" \
                      '"' + str(result'longitude']) + '"' +"|" \
                      '"' + str(result'name']) + '"' +"|" \
                      '"' + str(result'timezone']) + '"' +"|" \
                      '"' + str(datetime.now()) + '"' + "
")


        
#Write the data and errors returned by the API to flat files:
DestinationFile = open("C:\LatestAirportInfo.txt","w")
DestinationFile.writelines(ResultList)
DestinationFile.close()

ErrorDestinationFile = open("C:\LatestAirportInfoErrorLog.txt","w")
ErrorDestinationFile.writelines(ErrorList)
ErrorDestinationFile.close()

print "Saved information to C:\LatestAirportInfo.txt"
print "Saved errors to C:\LatestAirportInfoErrorLog.txt"


I’m not sure what to do to fix this, any assistance would be much appreciated. As a start - what codepage is used by Flightaware?

We use UTF-8 to avoid codepage issues.

Are you sure it is necessary to single-quote your airport codes? I don’t think the ’ sequence will ever work.

We use UTF-8 to avoid codepage issues.

Okay thanks, got it.

Are you sure it is necessary to single-quote your airport codes? I don’t think the ’ sequence will ever work.

My code was copied from a loop that I was using to insert all the airport codes I got back from the AllAirports operation. You’re right I shouldn’t have left those single quotes in. However when I simplify as follows I still get an error for some, but not all of the airports that I downloaded using the AllAirports operation:



import sys
from suds import null, WebFault
from suds.client import Client
import logging
from datetime import datetime

username = 'myusername'
apiKey = 'myapiKey'
url = 'http://flightxml.flightaware.com/soap/FlightXML2/wsdl'

logging.basicConfig(level=logging.INFO)
api = Client(url, username=username, password=apiKey)
#print api

# Get the latest flights for the requested tail number:
result = api.service.AirportInfo('AGGH')
print result



The error when I request info for AGGG is as follows: (note that this error is a bit more detailed than what I had seen using the previously copied code, it appears that the fault is actually ‘unknown airport’, not a codepage issue):

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0=“http://flightxml.flightaware.com/soap/FlightXML2” xmlns:ns1=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”>
SOAP-ENV:Header/
ns1:Body
ns0:AirportInfoRequest
ns0:airportCodeAGGG</ns0:airportCode>
</ns0:AirportInfoRequest>
</ns1:Body>
</SOAP-ENV:Envelope>

Traceback (most recent call last):
File “E:\2013 04 25 AirportInfo request.py”, line 17, in
result = api.service.AirportInfo(‘AGGG’)
File “C:\Python27\lib\site-packages\suds\client.py”, line 542, in call
return client.invoke(args, kwargs)
File “C:\Python27\lib\site-packages\suds\client.py”, line 602, in invoke
result = self.send(soapenv)
File “C:\Python27\lib\site-packages\suds\client.py”, line 649, in send
result = self.failed(binding, e)
File “C:\Python27\lib\site-packages\suds\client.py”, line 702, in failed
r, p = binding.get_fault(reply)
File “C:\Python27\lib\site-packages\suds\bindings\binding.py”, line 265, in get_fault
raise WebFault(p, faultroot)
WebFault: Server raised fault: ‘unknown airport AGGG’

I do not get any error back for many other airports, like AGGH, 83Q etc. For example the code prints the following for AGGH:

(AirportInfoStruct){
name = “Honiara Int’l”
location = “Honiara, Guadalcanal”
longitude = 160.053614
latitude = -9.427944
timezone = “:Pacific/Guadalcanal”
}

Not all the airport codes have enough information to be returned by FlightXML. Currently about 1% of the airport codes in our database (mostly small ones with no current flight data) are missing latitude/longitude information, which is required for it to be returned by AirportInfo.

Okay thanks, understood.

Just to follow up, the AllAirports method was modified last week to no longer return airport codes that are known to fail with AirportInfo.