0

「import pyodbc」を介して SQL からデータを取得する Python スクリプトを作成しました。このスクリプトがプルするデータは、テキスト メッセージ ゲートウェイ API に解析され、それに応じてテキスト メッセージが顧客に送信されます。これは python でうまく動作します。

ただし、今、ビジネスで新しい請求書が生成されるたびに実行される SQL ストアド プロシージャを作成したいと考えています。電話番号 + メッセージのデータを、同じ SQL ストアド プロシージャ内のこの python python スクリプトに送信します。

私が今抱えている問題は、この python scrip を ssms 2017 で記述し、構文エラーなしで実行することです。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.
4

1 に答える 1