There a way to debug the execution of the script in FME?
In a process in my company we use a Python script (PythonCaller) to call a download API, we need to modify it, but we get some errors that I don't get when running the script from Python on the Windows command line.
Is there a way to debug the execution of the script in FME?
If possible, I try to avoid using Python and use baked-in FME functionality as much as possible I don't know if it's an option here, but maybe you could consider an HTTPCaller to perform your downloadAPI calls?
I`ll try using HTTPCaller to perform my download API calls?
With some fiddeling it is possible. After working on a project which grew very fast in complexity FMEs transformers could not handle it and the python code grew to much so i spent some time banging my head against the wall.
After some time i found this post about developing FME packages that mentioned debugpy, but the same principle applies to running pythoncallers.
Install debugpy package into an existing python installation (Esri ArcGIS Python 3.9 for me, and i used PIP). This MAY cause instability with your existing python installation. We use an existing python installation because FME refused to accept a custom one, plus we make sure its compatible with FME Server.
In the same folder as your FME-file, create a python file (.py). In that python module, paste the default python-code
Create another python module, debug.py and add the following code
# Debug -> Attach to process -> tcp://127.0.0.1:5678
def start_debugging(): import fme if fme.macroValues.get('FME_SERVER_HOST') == '': print('Running locally') import psutil targets = 'devenv.exe', 'code.exe'] # Visual Studio and VSCode processes = sorted(proc.name() for proc in psutil.process_iter(c'name'])])
if any(target in processes for target in targets): print('Visual Studio or VSCode running, enabling debugging') import debugpy
socket = ("127.0.0.1", 5678) print('Starting debugging session...') print('Setting path') debugpy.configure(python=r'C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe') print('Trying to listen') debugpy.listen(socket) print(f'Listening ... waiting for debugger to connect to socket {socket}. \nIn Visual Studio -> Debugging -> Attach to process, connect to tcp://127.0.0.1:5678') debugpy.wait_for_client() print('Client connected') # debugpy.breakpoint() # Optional: Set a breakpoint right after else: print('Visual studio or VSCode not running, no debugging enabled')
else: print('Running on server, no debugging')
# Use this method to find the python path to use in the debugpy.configure line def print_python_paths(): import sys print(f'System version {sys.version_info}')
for path in sys.path: print(f'System path {path}')
Create a PythonCaller add the following code”. Make sure that the “Class to Process Features has the same name as the class you are importing.
In Visual Studio (VS Code works as well) create a new Python project. Under Python Environments add the arcgispro-py3 one and set it to active. It will now fild all installed packages.
To not get errors from fme and fmeobjects, copy the .py and .pyd files from the python installation you are using into the same folder that your fme-file and python modules are
fme.py
fmebootstrap.py
fmeobjects.cp39-win_amd64.pyd
When you start your script you should see this text
So go ahead and connect your debugger and enjoy breakpoints, code completion, copilot, linting and everything else that comes with a good IDE