Skip to main content
Solved

Why does my scripted parameter fail, when I use a User Parameter as input ?

  • October 28, 2021
  • 2 replies
  • 70 views

Forum|alt.badge.img

I need to check the encoding of several files.

For this I can use a scripted parameter like so:

 

featureType =open('F:\\PGV\\Projektarbejdsmapper\\P4\\SCSV_til_kontrol\\scsv_2021e1_2021e3\\\\2021e1_lev_k_fortidsminde.scsv')

t = str(featureType)

return t

 

With a Creator and a ParameterFetcher i get the following attribute:

<_io.TextIOWrapper name='F:\\\\PGV\\\\Projektarbejdsmapper\\\\P4\\\\SCSV_til_kontrol\\\\scsv_2021e1_2021e3\\\\2021e1_lev_k_fortidsminde.scsv' mode='r' encoding='cp1252'>

 

When I try to do this with a useparameter like so:

 

file = FME_MacroValues['SCSV_file']

featureType =open(file)

t = str(featureType)

return t

 

This returns the following log:

Starting translation...

INFORM: Using Python interpreter from `C:\\Program Files\\FME\\fmepython38\\python38.dll' with PYTHONHOME `C:\\Program Files\\FME\\fmepython38'

INFORM: Python version 3.8 loaded successfully

ERROR : Python Exception <KeyError>: 'SCSV_file'

INCLUDE -- failed to evaluate Python script `def ParamFunc():

file = FME_MacroValues['SCSV_file']

featureType =open(file)

t = str(featureType)

return t

value = ParamFunc()

macroName = 'test_script'

if value == None:

return { macroName : u'' }

else:

import six

try:

value = six.text_type(value)

except UnicodeDecodeError:

value = six.text_type(value, 'utf-8')

return { macroName : value }

'

Program Terminating

Translation FAILED.

 

Why does my scripted parameter fail, when I use a User Parameter (text) as input ? 

Best answer by david_r

The Python exception reads:

ERROR : Python Exception <KeyError>: 'SCSV_file'

Which means that the scripted parameter cannot find a parameter named 'SCSV_file'. Two things to check:

  1. If 'SCSV_file' is a private parameter, make sure that it is listed before the scripted parameter. The parameters are executed top-down.
  2. Make sure that 'SCSV_file' corresponds to the actual parameter name, the name is case sensitive
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • 8392 replies
  • Best Answer
  • October 28, 2021

The Python exception reads:

ERROR : Python Exception <KeyError>: 'SCSV_file'

Which means that the scripted parameter cannot find a parameter named 'SCSV_file'. Two things to check:

  1. If 'SCSV_file' is a private parameter, make sure that it is listed before the scripted parameter. The parameters are executed top-down.
  2. Make sure that 'SCSV_file' corresponds to the actual parameter name, the name is case sensitive

Forum|alt.badge.img
  • Author
  • 41 replies
  • October 28, 2021

The Python exception reads:

ERROR : Python Exception <KeyError>: 'SCSV_file'

Which means that the scripted parameter cannot find a parameter named 'SCSV_file'. Two things to check:

  1. If 'SCSV_file' is a private parameter, make sure that it is listed before the scripted parameter. The parameters are executed top-down.
  2. Make sure that 'SCSV_file' corresponds to the actual parameter name, the name is case sensitive

Thank you so much!

Had the SCSV_File parameter after the scripted one 🙈