Erro in suds when consulting wsdl

1

I'm migrating some projects to python on sql 2017, and I ran into a problem about the suds library.

EXEC sp_execute_external_script 
@language = N'Python', 
@script = N'
from suds.client import Client
url="https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl"
client = Client(url)'

Exit

  

Msg 39004, Level 16, State 20, Line 0 Script error 'Python' during   the execution of 'sp_execute_external_script' with HRESULT 0x80004004.   Msg 39019, Level 16, State 2, Line 0 Error in external script:

     

Error in execution. Check the output for more information. Traceback   (most recent call last): File "", line 5, in File   "D: \ MSSQL \ MSSQL14.MSSQLSERVER \ MSSQL \ ExtensibilityData \ MSSQLSERVER01 \ 2BB630CA-1241-4B83-B33A-195C1B7C98A2 \ sqlindb.py",   line 29, in transform       from suds.client import Client File "D: \ MSSQL \ MSSQL14.MSSQLSERVER \ PYTHON_SERVICES \ lib \ site-packages \ suds \ client.py",   line 242       except Exception, e:                       ^ SyntaxError: invalid syntax

     

SqlSatelliteCall error: Error in execution. Check the output for more   information. STDOUT message (s) from the external script: SqlSatelliteCall   function failed. Please see the console output for more information.   Traceback (most recent call last): File   "D: \ MSSQL \ MSSQL14.MSSQLSERVER \ PYTHON_SERVICES \ lib \ site-packages \ revoscalepy \ computecontext \ RxInSqlServer.py",   line 406, in rx_sql_satellite_call       rx_native_call ("SqlSatelliteCall", params) File "D: \ MSSQL \ MSSQL14.MSSQLSERVER \ PYTHON_SERVICES \ lib \ site-packages \ revoscalepy \ RxSerializable.py",   line 291, in rx_native_call       ret = px_call (functionname, params) RuntimeError: revoscalepy function failed.

It is in the line in question where the exception of the client.py file occurs

def create(self, name):
        """
        create a WSDL type by name
        @param name: The name of a type defined in the WSDL.
        @type name: str
        @return: The requested object.
        @rtype: L{Object}
        """
        timer = metrics.Timer()
        timer.start()
        type = self.resolver.find(name)
        if type is None:
            raise TypeNotFound(name)
        if type.enum():
            result = InstFactory.object(name)
            for e, a in type.children():
                setattr(result, e.name, e.name)
        else:
            try:
                result = self.builder.build(type)
            except Exception, e:
                log.error("create '%s' failed", name, exc_info=True)
                raise BuildError(name, e)
        timer.stop()
        metrics.log.debug('%s created: %s', name, timer)
        return result 

the python version is 3.5.2 Continuum.

    
asked by Sebastian 27.05.2018 в 17:28
source

1 answer

1

This code is not valid for Python 3, the syntax for associating an exception with a local variable was changed based on what is stated in PEP 3110 .

You must use as to assign the exception to the local variable e , valid syntax since version 2.6:

try:
    result = self.builder.build(type)
except Exception as e:
    log.error("create '%s' failed", name, exc_info=True)
    raise BuildError(name, e)

In Python 2, the syntax for capturing exceptions was:

  • except ExceptionType:

  • except ExceptionType, target:

ExceptionType can be a tuple, eg: except (TypeError, ValueError) .

This syntax is ambiguous and could cause errors that are difficult to detect, if we do:

except TypeError, ValueError: # Without parentheses

will only capture TypeError and assign the object to the identifier ValueError , which also masks the built-in.

To solve this, Python 2.6 introduced an alternative syntax:

except ExceptionType as target:

In Python 3, the above syntax is no longer allowed, in Python> = 2.6 it was maintained to maintain compatibility with previous versions.

  

Note : type is a built-in function, this identifier should not be used for own variables. in this case it is a local variable so it is only overwritten within the function, however if only for readability another name or type_ should be used.

    
answered by 27.05.2018 / 17:55
source