3

Python script in model: ok in preview, fails at runtime

Hello everyone.

I am attempting to execute a python script module in Model. The key library I am using is googletrans, which allows API calls to Google translate to facilitate foreign language translations.

I am finding that the preview pane displays output as I would expect. The preview size is set to be larger than the number of rows in the dataset. Has this happened to other users, i.e. preview is as expected, but runtime fails.

Thrown error message is appended below.

Best wishes,

Dave

 

[17:26:58] - scripting error: Scripting process execution for the following command has failed:
C:\Program Files\Pyramid\python\Scripts\conda run -p C:\Program Files\Pyramid\repository\general\scripting_Environments\84d68e1a-69f6-489c-b76a-b8e5984c6a3e python C:\Program Files\Pyramid\repository\general\6b8fc145-1539-487e-be22-2eae7bfc331f.py C:\\Program Files\\Pyramid\\repository\\general\\8a0c2f87-ff56-468d-9bd3-56f6a8b05352.csv '' '' '' ''
Traceback (most recent call last):

  Pyramid Script, line 14, in <module>

    p = translator.translate(r[1], src='fr', dest='en').text

  File "C:\Program Files\Pyramid\repository\general\scripting_Environments\84d68e1a-69f6-489c-b76a-b8e5984c6a3e\lib\site-packages\googletrans\client.py", line 194, in translate

    data, response = self._translate(text, dest, src)

  File "C:\Program Files\Pyramid\repository\general\scripting_Environments\84d68e1a-69f6-489c-b76a-b8e5984c6a3e\lib\site-packages\googletrans\client.py", line 122, in _translate

    if r.status_code != 200 and self.raise_Exception:

AttributeError: 'Translator' object has no attribute 'raise_Exception'. Did you mean: 'raise_exception'?

ERROR conda.cli.main_run:execute(47): `conda run python C:\Program Files\Pyramid\repository\general\6b8fc145-1539-487e-be22-2eae7bfc331f.py C:\\Program Files\\Pyramid\\repository\\general\\8a0c2f87-ff56-468d-9bd3-56f6a8b05352.csv '' '' '' ''` failed. (See above for error)
 

3 replies

null
    • Nadav
    • 5 mths ago
    • Reported - view

    Hi Dave can you please also include the script you are using? In general, it looks like there is a specific row that is sent to the script in runtime but not in preview, that is causing the error. it might be helpful to debug it, to translate one row at a time (if it isn't doing so already), catching the exception, and outputing the problematic text that it fails translating

      • Dave_Carbery
      • 5 mths ago
      • Reported - view

      Hello Nadav, thank you for the reply and question.

      Here is the script that is in the python node:

      import pandas as pd
      import numpy as np
      from googletrans import Translator

      translator = Translator()

      inputDF['item_en'] = np.nan

      ph = []

      for r in inputDF.itertuples():
          p = translator.translate(r[1], src='fr', dest='en').text
          ph.append(p)

      inputDF['item_en'] = ph

      outputDF = inputDF

    • Nadav
    • 5 mths ago
    • Answer
    • Reported - view

    Thank you Dave. I'm pretty certain that the problem is in one or more data rows that are handed to the script during the runtime execution but not in the preview sample. I suggest wrapping the "p = translator.translate(r[1], src='fr', dest='en').text" line with try catch, and just ignore rows that failed. I would suggest setting some fall back value to variable 'p' in the catch, for example 'Translation Failed' or '' or the original, non translated value, or None. I hope this helps.

    After it executes you can filter in discovery only the rows with the fallback value and may be try to guess why those rows could not have been translated

Content aside

  • Status Answered
  • 3 Likes
  • 5 mths agoLast active
  • 3Replies
  • 158Views
  • 3 Following