Not sure it this really helps you, but I have found adding a ParameterFetcher before the a python caller can make things a little easier to work with. Get the [FME_SHARERESOURCE_DATA] as an attribute.
Keep in mind that When working in Desktop the FME_SHARERESOURCE_DATA] will be empty because this us only used in FME Server.
My Problem is related to the server not to desktop. In the workbench i can read the directory on [FME_SHARERESOURCE_DATA] with the "Directory and File Pathnames Reader" successfully and then I can analyse the lasted filename as a attribut. But then the access the file in the python script is not possible.
You can access the parameter value in Python like this:
fmeserver_data = fme.macroValues.get('FME_SHAREDRESOURCE_DATA')
if fmeserver_data:
# Note that FME_SHAREDRESOURCE_DATA is usually undefined on Desktop
with open(fmeserver_data+'/filename.txt', 'r') as f:
contents = f.readlines()
thanks.
Why it is not possible to use the path_unix attribut directly?
# attribute from the Directory and File Pathnames Reader
feature.getAttribute('path_unix')
thanks.
Why it is not possible to use the path_unix attribut directly?
# attribute from the Directory and File Pathnames Reader
feature.getAttribute('path_unix')
Is it not? That is surprising. What is the value of 'path_unix'? What is the error message?
json_file_new = feature.getAttribute('path_unix')
logger.logMessageString("FME_SHAREDRESOURCE_DATA: %s"%(shared_resource_data_path))
logger.logMessageString("PATH_UNIX: %s"%(json_file_new))
json_data_new = codecs.open(json_file_new,encoding="UTF-8",mode="r")
LOG-FILE
279 2021-11-11 12:18:56 | FME_SHAREDRESOURCE_DATA: /data/fmeserver/resources/data/
280 2021-11-11 12:18:56 | PATH_UNIX: /data/fmeserver/resources/data/xxx/xxxx/xxxxxx/xxxxxxxx/yyyyyyyyy_20211111.json
281 2021-11-11 12:18:57 | Python Exception <TypeError>: expected str, bytes or os.PathLike object, not NoneType
282 2021-11-11 12:18:57 | Traceback (most recent call last):
283 2021-11-11 12:18:57 | File "<string>", line 37, in input
284 2021-11-11 12:18:57 | File "/usr/lib/python3.6/codecs.py", line 897, in open
285 2021-11-11 12:18:57 | file = builtins.open(filename, mode, buffering)
286 2021-11-11 12:18:57 | TypeError: expected str, bytes or os.PathLike object, not NoneType
287 2021-11-11 12:18:57 |
288 2021-11-11 12:18:57 | Error encountered while calling method `input'
289 2021-11-11 12:18:57 | PythonCaller (PythonFactory): PythonFactory failed to process feature
FME Version
FME Server 2020.2.1
Build 20806 - linux-x64
json_file_new = feature.getAttribute('path_unix')
logger.logMessageString("FME_SHAREDRESOURCE_DATA: %s"%(shared_resource_data_path))
logger.logMessageString("PATH_UNIX: %s"%(json_file_new))
json_data_new = codecs.open(json_file_new,encoding="UTF-8",mode="r")
LOG-FILE
279 2021-11-11 12:18:56 | FME_SHAREDRESOURCE_DATA: /data/fmeserver/resources/data/
280 2021-11-11 12:18:56 | PATH_UNIX: /data/fmeserver/resources/data/xxx/xxxx/xxxxxx/xxxxxxxx/yyyyyyyyy_20211111.json
281 2021-11-11 12:18:57 | Python Exception <TypeError>: expected str, bytes or os.PathLike object, not NoneType
282 2021-11-11 12:18:57 | Traceback (most recent call last):
283 2021-11-11 12:18:57 | File "<string>", line 37, in input
284 2021-11-11 12:18:57 | File "/usr/lib/python3.6/codecs.py", line 897, in open
285 2021-11-11 12:18:57 | file = builtins.open(filename, mode, buffering)
286 2021-11-11 12:18:57 | TypeError: expected str, bytes or os.PathLike object, not NoneType
287 2021-11-11 12:18:57 |
288 2021-11-11 12:18:57 | Error encountered while calling method `input'
289 2021-11-11 12:18:57 | PythonCaller (PythonFactory): PythonFactory failed to process feature
FME Version
FME Server 2020.2.1
Build 20806 - linux-x64
Weird. What happens if you hard-code the filename into the call to codecs.open()? Does that work?
Can you also try to log the following to check what the object type of json_file_new is:
logger.logMessageString("type of json_file_new: %s" % type(json_file_new))
Hi david,
i found the problem. The second attribut for the second file was not set successfully. Now the PythonCaller works fine.
Thanks for your help
Kind regards
Stefan
Hi david,
i found the problem. The second attribut for the second file was not set successfully. Now the PythonCaller works fine.
Thanks for your help
Kind regards
Stefan
Thanks, glad to hear you got it working.