FAILING on FlightAware sample code


#1

Hello,

This is my first time posting here. I’m trying to run through the sample code first before attempting my own project. I selected Python version that uses SOAPpy


from SOAPpy import Config, HTTPTransport, SOAPAddress, WSDL

username = 'myusername'
apiKey = '0axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

wsdlFile = 'http://flightxml.flightaware.com/soap/FlightXML2'

# This is a custom HTTP transport that allows Basic Authentication.
class myHTTPTransport(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=Config):

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

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

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


# Make a FlightXML server request.
myHTTPTransport.setAuthentication(username, apiKey)
DF = WSDL.Proxy(wsdlFile, transport=myHTTPTransport)

enroute = DF.Enroute('KSMO',10,'',0)

flights = enroute'enroute']

print "Aircraft en route to KSMO:"
for flight in flights:
    print "%s (%s) 	%s (%s)" % ( flight'ident'], flight'aircrafttype'],
                              flight'originName'], flight'origin'])

The code throws the exact same error for me using my username/apikey pair as it does for the sample stuff that was provided.

The error I get is as follows:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\XXXX\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "C:\XXXX\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "FlightAwareSample.py", line 42, in <module>
    DF = WSDL.Proxy(wsdlFile, transport=myHTTPTransport)
  File "C:\XXXX\Anaconda\lib\site-packages\SOAPpy\WSDL.py", line 85, in __init__
    self.wsdl = reader.loadFromString(str(wsdlsource))
  File "C:\XXXX\Anaconda\lib\site-packages\wstools\WSDLTools.py", line 52, in loadFromString
    return self.loadFromStream(StringIO(data))
TypeError: initial_value must be unicode or None, not str

Note: I’ve redacted some of the file paths

When I spoke with support they said that my username/apikey pair was correct. I do get the following error when I try to go to http://flightxml.flightaware.com/soap/FlightXML2 which is the wsdlFile

Gone

The requested resource
/soap/FlightXML2
is no longer available on this server and there is no forwarding address. Please remove all references to this resource.

Any help you can offer would be much appreciated


#2

Try changing the path to the wsdl file to be:
flightxml.flightaware.com/soap/FlightXML2/wsdl


#3

Thank you for your reply. Same exact error message for the changed path. Unfortunately


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\XXXX\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "C:\XXXX\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "FlightAwareSample.py", line 42, in <module>
    DF = WSDL.Proxy(wsdlFile, transport=myHTTPTransport)
  File "C:\XXXX\Anaconda\lib\site-packages\SOAPpy\WSDL.py", line 85, in __init__
    self.wsdl = reader.loadFromString(str(wsdlsource))
  File "C:\XXXX\Anaconda\lib\site-packages\wstools\WSDLTools.py", line 52, in loadFromString
    return self.loadFromStream(StringIO(data))
TypeError: initial_value must be unicode or None, not str


#4

Are you using Python 2 or Python 3? I believe that example will only work with Python 2.


#5

I’m getting a different error when I try and run the sample code for SOAP in Python. I changed the URL to include the /WSDL suffix and now I get this:

DF = WSDL.Proxy(wsdlFile, transport=myHTTPTransport)

Traceback (most recent call last):
File “<pyshell#2>”, line 1, in
DF = WSDL.Proxy(wsdlFile, transport=myHTTPTransport)
File “C:\Python27\lib\site-packages\SOAPpy\WSDL.py”, line 97, in init
callinfo = wstools.WSDLTools.callInfoFromWSDL(port, operation.name)
File “C:\Python27\lib\site-packages\wstools\WSDLTools.py”, line 1607, in callInfoFromWSDL
logger = logging.getLogger(name)
NameError: global name ‘logging’ is not defined

If I pass in a faulty URL in the WSDLFile argument I get a different error, which leads me to believe that WSDLTools is struggling somehow.


#6

That seems like you need to initialize the logging subsystem first? Did you make any other changes to the example to cause logging to be a requirement now?


#7

I’ve made no changes, other than the URL and my own API key. It is possible that WSDLTools was has bee updated to require logging?

I’m in Python 2.7.13, WSTools 0.4.4


#8

I gave up on SOAPpy. It works fine in suds.


#9

The logging issue only exists with wstools 0.4.4. You’ll need to either downgrade wstools to 0.4.3 or upgrade to 0.4.6. The 0.4.5 version has a different issue with SOAPpy where SOAPpy calls callInfoFromWSDL with the wrong number of arguments.