我写了一个python脚本,通过"import pyodbc“从sql获取数据,这个脚本提取的数据被解析成文本消息网关API,从而相应地向客户发送文本消息。这在python中工作得很好。
但是,现在我想编写一个sql存储过程,它将在我的业务中每次生成新发票时运行,将电话号码+消息的数据发送到同一sql存储过程中的python python脚本。
我现在遇到的问题是用ssms 2017编写这个python脚本,并在没有语法错误的情况下执行它。考虑到我使用的是sql 2017,我已经分别启用了python和r。
execute sp_execute_external_script
@language = N'Python',
@script = N'
import africastalking
username = "sandbox"
apikey = "bf62be6"
africastalking.initialize(username, apikey)
sms = africastalking.SMS
recipients = ["+254797301255"]
message = ["Test from SQL"]
sender = "MegaLtd"
try:
response = sms.send(message, recipients, sender)
print(response)
except Exception as e:
print(f"Houston, we have a problem {e}")
'这是我收到的错误
Msg 39004, Level 16, State 20, Line 2
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 2
An external script error occurred:
Error in execution. Check the output for more information.
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "C:\PROGRA~1\MICROS~3\MSSQL1~1.MPR\MSSQL\EXTENS~1\MPRYCESQLSEVER01\1D611E8A-CDE1-4F30-9FAC-0BB13871A3DE\sqlindb.py", line 59
print(f"Houston, we have a problem {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 "C:\Program Files\Microsoft SQL Server\MSSQL14.MPRYCESQLSEVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 406, in rx_sql_satellite_call
rx_native_call("SqlSatelliteCall", params)
File "C:\Program Files\Microsoft SQL Server\MSSQL14.MPRYCESQLSEVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 291, in rx_native_call
ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.发布于 2019-05-13 20:51:51
您的环境很可能使用Python 3.5.2
但是,在Python 3.6中引入了f字符串
所以你要么升级你的Python,要么重写异常处理,例如:
# ORIG: print(f"Houston, we have a problem {e}")
print("Houston, we have a problem {}".format(e))如果您不确定环境使用的是哪个Python版本,可以查看
import sys
print(sys.version)https://stackoverflow.com/questions/56112634
复制相似问题