microsoft / microsoft/sql-server-samples
Error while running Python script from sql server
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 11.2k
- Forks
- 9.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 14
Description
Hi ,
I am trying to call the python script from the sql server.
EXEC sp_execute_external_script
@language = N'Python',
@script = N'import time
import sys
import codecs
import os
myfile = codecs.open(D:\SAP_Download\TPM_MATERIAL_MASTER_20191209_101848.txt, encoding=''utf-8'')
marylines = myfile.readlines()
myfile1 = codecs.open(D:\SAP_Download\TPM_MATERIAL_MASTER_20191209_101848.txt, ''w'', encoding=''utf-16'')
for line in marylines:
myfile1.write(line)
myfile1.close()
myfile.close()';
And getting below error
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 8
An external script error occurred:
Error in execution. Check the output for more information.
Traceback (most recent call last):
File "", line 3, in
File "C:\ProgramData\MSSQLSERVER\Temp-PY\Appcontainer1\5A4DD7D3-68C1-4299-8841-E3A74C93E65F\sqlindb_0.py", line 37
myfile = codecs.open(D:\SAP_Download\TPM_MATERIAL_MASTER_20191209_101848.txt, encoding='utf-8')
^
SyntaxError: invalid syntax
SqlSatelliteCall error: Error in execution. Check the output for more information.
STDOUT message(s) from external script:
Express Edition will continue to be enforced.
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the inline EXEC sp_execute_external_script call and the Python traceback, especially the codecs.open lines identified in the generated sqlindb_0.py file. Reproduce the reported execution path and verify that the script completes without the shown SyntaxError and external-script failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100