SQL 2019 ML Python Error

CSource 41 Reputation points
2022-06-15T15:24:17.417+00:00

Recently updated to SQL 2019 and installed Python successfully.

When i try to run a test command :

execute sp_execute_external_script
@language = N'Python',
@script = N'
a = 9
b = 3
c = a/b
d = a*b
print(c, d)
'

I get an error:

Msg 39004, Level 16, State 20, Line 0
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 0
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:\ProgramData\MSSQLSERVER\Temp-PY\Appcontainer1\18AB6DA4-D653-44FB-B496-874B988DD645\sqlindb_0.py", line 31
a = 9
^
IndentationError: unexpected indent

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\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 605, in rx_sql_satellite_call
rx_native_call("SqlSatelliteCall", params)
File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 375, in rx_native_call
ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.

Completion time: 2022-06-15T11:20:30.3104794-04:00

I see threads on providing access to certain folders but this is native, help is very much appreciated

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Seeya Xi-MSFT 16,586 Reputation points
    2022-06-16T08:16:35.113+00:00

    Hi @CSource ,

    Welcome to Microsoft Q&A!
    You are using Python scripts with SQL Server, you can use a true Python editor, like VS Code, and not rely on using SSMS. If your indents are incorrect, you will see an error message similar to this:
    Msg 39004, Level 16, State 20, Line 0
    A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
    Msg 39019, Level 16, State 2, Line 0
    An external script error occurred:

    The error is clear: "unexpected indent." The error message also points to the exact spot. But you could have many such errors in future. That's why using VS Code would be handy, and you can then cut and paste the script into your procedure.

    Best regards,
    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-06-15T21:20:00.223+00:00

    Your script executed successfully when I tried it.

    However, the error message suggests some spaces may have been lost in your post. To wit, this runs:

       execute sp_execute_external_script  
       @language = N'Python',  
       @script = N'  
       a = 9  
       b = 3  
       c = a/b  
       d = a*b  
       print(c, d)  
       '  
    

    But this produces the error you got:

       execute sp_execute_external_script  
       @language = N'Python',  
       @script = N'  
          a = 9  
          b = 3  
          c = a/b  
          d = a*b  
          print(c, d)  
       '  
    

    Recall that in difference to most other languages, indentation is syntactically significant in Python.

    By the way, to insert a code snippet in your post, use the button with ones and zeroes.

    0 comments No comments

  2. CSource 41 Reputation points
    2022-06-16T18:34:18.033+00:00

    Thank you, indentation error (code was copied and looked to be indented but wasn't) user err.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.