Skip to main content
Solved

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


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
View original
Did this help you find an answer to your question?

2 replies

david_r
Celebrity
  • 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
david_r wrote:

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 🙈 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings