Python Example

Hi, Here is a simple python example using SOAPpy. A bit trick at first, til I figured out the HttpResponse stuff … Enjoy



import SOAPpy

class myHTTPTransport(SOAPpy.HTTPTransport):
    username = None
    passwd = None

    @classmethod
    def setAuthentication(cls,u,p):
        cls.username = u
        cls.passwd = p

    def call(self, addr, data, namespace, soapaction=None, encoding=None,
             http_proxy=None, config=SOAPpy.Config):

        if not isinstance(addr, SOAPpy.SOAPAddress):
            addr=SOAPAddress(addr, config)

        if self.username != None:
            addr.user = self.username+":"+self.passwd

        return SOAPpy.HTTPTransport.call(self, addr, data, namespace, soapaction,
                                  encoding, http_proxy, config)


wsdlFile = 'http://flightaware.com/commercial/directflight/data/wsdl1.xml'
myHTTPTransport.setAuthentication('USERNAME', 'CHANGE THIS TO YOUR API KEY')
server = SOAPpy.WSDL.Proxy(wsdlFile, transport=myHTTPTransport)
print server.FlightInfo(ident='AAL1684',howMany=1)


It’s not really that simple, is it?

Yep, works for me. Had to subclass the HTTPTransport in order to pass the credentials, but no problem after that. Looking through results like this


results = server.FlightInfo(ident='AAL121',howMany=1)
print results
for flight in results.flights:
	print flight.ident + ' ' + str(time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(flight.filed_departuretime))) + ' ' + str(flight.filed_ete) + ' ' + flight.origin + ' ' + flight.route + ' ' + flight.destination

Let me know if you have further questions.