Solved

Use of FME_SERVER_HOST parameter on Desktop

  • 8 February 2018
  • 2 replies
  • 2 views

Badge +11

Hi all, 

I have two environments of FME Server: dev and prod. Based on the hostname, I want to set several parameters:

  • FME Server connection for notification
  • Email addresses are different
  • ...

I do this with very simple Python scripts like:

_hostname = FME_MacroValues['FME_SERVER_HOST']

if _hostname == 'XXXXXXXXXXX':
    FME_Connection = 'fmeserver_prod'
else:
    FME_Connection = 'fmeserver_dev'

return FME_Connection

This works well on FME Server, but I cannot run this Workspace any more on Desktop. When filling in a value for FME_SERVER_HOST on Desktop, Python does not seem to be able to get to the FME_MacroValues. Anyone some advice on how to solve this?

icon

Best answer by takashi 8 February 2018, 13:24

View original

2 replies

Userlevel 2
Badge +17

Hi @jelle, naturally FME Server parameters won't be defined in Desktop environment, so the FME_MacroValues dictionary may not have the key (parameter name) and value pairs for those parameters. I think you encountered KeyError from the Python interpreter.

There are at least two workaround.

1. Use the 'in' operator to determine if the dictionary contains the key. If the key doesn't exist, do something you need.

or

2. Use the 'get' method of dict class to get the value. The method returns default value if the key doesn't exist, so you can determine if the key exists based on the return value.

Badge +11

Hi @jelle, naturally FME Server parameters won't be defined in Desktop environment, so the FME_MacroValues dictionary may not have the key (parameter name) and value pairs for those parameters. I think you encountered KeyError from the Python interpreter.

There are at least two workaround.

1. Use the 'in' operator to determine if the dictionary contains the key. If the key doesn't exist, do something you need.

or

2. Use the 'get' method of dict class to get the value. The method returns default value if the key doesn't exist, so you can determine if the key exists based on the return value.

Hi Takashi, thank you for your answer. I was already looking in the direction of the get method. Combined with your answer on Multiple Parameters, I was able to solve my challenge. Learned again something today.

 

 

First, I create a parameter Get_Hostname

 

if FME_MacroValues.get('FME_SERVER_HOST', None):
    print 'Server'
    return FME_MacroValues['FME_SERVER_HOST']
else:
    print 'Desktop'
    global FME_MacroValues_Desktop
    FME_MacroValues_Desktop = {'FME_SERVER_HOST':'YYYYYYYYY'}
    return FME_MacroValues_Desktop['FME_SERVER_HOST']
Then, I have a second parameter called FME_Connection

 

if FME_MacroValues.get('FME_SERVER_HOST', None):
    _hostname = FME_MacroValues['FME_SERVER_HOST']
else:
    _hostname = FME_MacroValues_Desktop['FME_SERVER_HOST']

if _hostname == 'XXXXXXXXX':
    FME_Connection = 'fmeserver_prod'
else:
    FME_Connection = 'fmeserver_dev'

return FME_Connection
Based on the FME_Connection parameter, I set some other parameters like E-mail addresses to send an e-mail to and the WebService URL I want to use in the HTTP Caller.

 

 

I hope this example helps for other people as well.

Reply