Solved

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

  • 28 October 2021
  • 2 replies
  • 20 views

Badge

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 ? 

icon

Best answer by david_r 28 October 2021, 13:02

View original

2 replies

Userlevel 4

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
Badge

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 🙈 

Reply