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)'
Departure
Msg 39004, Level 16, State 20, Line 0 'Python' script error during 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 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.
That code is not valid for Python 3, the syntax to associate an exception to a local variable was changed based on PEP 3110 .
You must use
as
to assign the exception to the local variablee
, syntax valid already since version 2.6:In Python 2, the syntax for catching exceptions was:
except ExceptionType:
except ExceptionType, target:
ExceptionType
can be a tuple, eg:except (TypeError, ValueError)
.This syntax is ambiguous and could cause hard-to-detect errors if we do:
except TypeError, ValueError:
# without parentheseswill only capture
TypeError
and assign the object to the identifierValueError
, which also masks the built-in.To fix this, Python 2.6 introduced an alternate syntax:
In Python 3 the old syntax is no longer allowed, in Python >= 2.6 it was kept for backward compatibility.