Python in Execute Process Task

huangapple go评论108阅读模式
英文:

Python in Execute Process Task

问题

我已经编写了一个Python代码,然后通过SSIS的"执行进程"任务来运行它。

该代码通过Google API(使用pip安装googletrans==4.0.0-rc1)来读取和写入SQL Management Studio以进行翻译,没有通过SSIS进行输入或输出。输入和输出是通过Python中的sqlalchemy完成的。

这段代码在Jupyter Notebook中运行得非常正常,并且我将其保存为.py文件,但是在SSIS的"执行进程"任务中出现了很多错误。

英文:

I have written a python code, then ran it through SSIS in the Execute Process Task.

The code reads and writes to SQL management studio to translate via Google API (pip install googletrans==4.0.0-rc1), with no output or input through SSIS. the input and output are done through sqlacademy in python.

The codes runs perfectly fine in Jupyter notebook, and I saved it to be .py file, but I face a lot of error in the Execute Process Task in SSIS.

答案1

得分: 0

以下是您要翻译的内容:

HelloWorld.err.py

A trivial python script that will write a string to standard out, another to standard error and the exit with return code 1.

  1. import sys
  2. print("Hello world")
  3. print("Egads, something bad happened!", file=sys.stderr)
  4. exit(1)

SSIS package

A sample SSIS package would look something like the following. An Execute Process Task has a successor of a Script Task.

[![enter image description here][1]][1]

Double click the precedent constraint (the line between the two) and change that from the default of Success to Completion

[![enter image description here][2]][2]

EPT Python

An Execute Package Task that is configured as shown

[![enter image description here][3]][3]

  • Executable: C:\Program Files\Python39\python.exe
  • Arguments: C:\ssisdata\SO_75361110.err.py
  • StandardOutputVariable: User::StdOut
  • StandardErrorVariabele: User::StdErr

SCR Echo Back

This is a generic Script Task that I use and abuse to dump the values of SSIS Variables to the output log/results tab. It's easy, lightweight and let's you print values without popups or any hard work.

All you need to do is add the Variable(s) in the readonly/readWrite collection. In this case, I selected User::StdOut and User::StdErr

  1. using System;
  2. using System.Data;
  3. using Microsoft.SqlServer.Dts.Runtime;
  4. using System.Windows.Forms;
  5. namespace ST_ede4b38a087c4724a71149ffc5ed6be9
  6. {
  7. [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
  8. public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  9. {
  10. public void Main()
  11. {
  12. bool fireAgain = false;
  13. foreach (Variable item in Dts.Variables)
  14. {
  15. Dts.Events.FireInformation(0, "SCR Echo Back", string.Format("{0}->{1}", item.QualifiedName, item.Value), "", 0, ref fireAgain);
  16. }
  17. Dts.TaskResult = (int)ScriptResults.Success;
  18. }
  19. enum ScriptResults
  20. {
  21. Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
  22. Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
  23. };
  24. }
  25. }

Results

When my package runs, as "expected" the SuccessValue from my run will be 1 given that I use exit(1) from the python script.

Let's see what the Output tab looks like

  1. SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\SO_75361110.dtsx" starting.
  2. Error: 0xC0029151 at EPT Python the thing, Execute Process Task: In Executing "C:\Program Files\Python39\python.exe" "C:\ssisdata\SO_75361110.err.py" at "", The process exit code was "1" while the expected was "0".
  3. Task failed: EPT Python the thing
  4. Warning: 0x80019002 at SEQC Do the thing: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
  5. Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdErr->Egads, something bad happened!
  6. Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdOut->Hello world
  7. Warning: 0x80019002 at SO_75361110: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
  8. SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\SO_75361110.dtsx" finished: Failure.
  9. The program '[68044] DtsDebugHost.exe: DTS' has exited with code 0 (0x0).
  10. Of note, are these two lines
  11. > Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdErr->Egads, something bad happened!
  12. > Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdOut->Hello world
  13. That's our Script Task echoing back the value of our Standard Out and Standard Error text streams. My suspicion is that given a "normal" run is 10 minutes and the runs from SSIS are measured in seconds, the process execution is throwing errors to the caller but nobody is listening. This will add a listener and give you better information to diagnose your root cause.
  14. [1]: https://i.stack.imgur.com/hhf97.png
  15. [2]: https://i.stack.imgur.com/sGunj.png
  16. [3]: https://i.stack.imgur.com/Ku4sY.png
  17. <details>
  18. <summary>英文:</summary>
  19. HelloWorld.err.py
  20. ====
  21. A trivial python script that will write a string to standard out, another to standard error and the exit with return code 1.
  22. import sys
  23. print(&quot;Hello world&quot;)
  24. print(&quot;Egads, something bad happened!&quot;, file=sys.stderr)
  25. exit(1)
  26. SSIS package
  27. ====
  28. A sample SSIS package would look something like the following. An Execute Process Task has a successor of a Script Task.
  29. [![enter image description here][1]][1]
  30. Double click the precedent constraint (the line between the two) and change that from the default of Success to Completion
  31. [![enter image description here][2]][2]
  32. EPT Python
  33. -----
  34. An Execute Package Task that is configured as shown
  35. [![enter image description here][3]][3]
  36. * Executable: C:\Program Files\Python39\python.exe
  37. * Arguments: C:\ssisdata\SO_75361110.err.py
  38. * StandardOutputVariable: User::StdOut
  39. * StandardErrorVariabele: User::StdErr
  40. SCR Echo Back
  41. ---
  42. This is a generic Script Task that I use and abuse to dump the values of SSIS Variables to the output log/results tab. It&#39;s easy, lightweight and let&#39;s you print values without popups or any hard work.
  43. All you need to do is add the Variable(s) in the readonly/readWrite collection. In this case, I selected `User::StdOut` and `User::StdErr`
  44. using System;
  45. using System.Data;
  46. using Microsoft.SqlServer.Dts.Runtime;
  47. using System.Windows.Forms;
  48. namespace ST_ede4b38a087c4724a71149ffc5ed6be9
  49. {
  50. [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
  51. public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  52. {
  53. public void Main()
  54. {
  55. bool fireAgain = false;
  56. foreach (Variable item in Dts.Variables)
  57. {
  58. Dts.Events.FireInformation(0, &quot;SCR Echo Back&quot;, string.Format(&quot;{0}-&gt;{1}&quot;, item.QualifiedName, item.Value), &quot;&quot;, 0, ref fireAgain);
  59. }
  60. Dts.TaskResult = (int)ScriptResults.Success;
  61. }
  62. enum ScriptResults
  63. {
  64. Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
  65. Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
  66. };
  67. }
  68. }
  69. Results
  70. ----
  71. When my package runs, as &quot;expected&quot; the SuccessValue from my run will be 1 given that I use `exit(1)` from the python script.
  72. Let&#39;s see what the Output tab looks like
  73. SSIS package &quot;C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\SO_75361110.dtsx&quot; starting.
  74. Error: 0xC0029151 at EPT Python the thing, Execute Process Task: In Executing &quot;C:\Program Files\Python39\python.exe&quot; &quot;C:\ssisdata\SO_75361110.err.py&quot; at &quot;&quot;, The process exit code was &quot;1&quot; while the expected was &quot;0&quot;.
  75. Task failed: EPT Python the thing
  76. Warning: 0x80019002 at SEQC Do the thing: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
  77. Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdErr-&gt;Egads, something bad happened!
  78. Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdOut-&gt;Hello world
  79. Warning: 0x80019002 at SO_75361110: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
  80. SSIS package &quot;C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\SO_75361110.dtsx&quot; finished: Failure.
  81. The program &#39;[68044] DtsDebugHost.exe: DTS&#39; has exited with code 0 (0x0).
  82. Of note, are these two lines
  83. &gt; Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdErr-&gt;Egads, something bad happened!
  84. &gt; Information: 0x0 at SCR Echo Back, SCR Echo Back: User::StdOut-&gt;Hello world
  85. That&#39;s our Script Task echoing back the value of our Standard Out and Standard Error text streams. My suspicion is that given a &quot;normal&quot; run is 10 minutes and the runs from SSIS are measured in seconds, the process execution is throwing errors to the caller but nobody is listening. This will add a listener and give you better information to diagnose your root cause.
  86. [1]: https://i.stack.imgur.com/hhf97.png
  87. [2]: https://i.stack.imgur.com/sGunj.png
  88. [3]: https://i.stack.imgur.com/Ku4sY.png
  89. </details>

huangapple
  • 本文由 发表于 2023年2月6日 20:07:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75361110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定