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?