Skip to main content

I'm using a PythonCaller to derive a database instance string to be used to populate an attribute.  The caller works fine until I introduce a python script derived private parameter which outputs an sde connection string.  The string works if I plug it directly into a reader, but fails if I use it as a macro value in the Python Caller.  The error references a dll but I am using the correct interpreter and all my python scripts (including this one until now) are running fine otherwise.  Any thoughts?  

 

Thanks

 

*note all location specific text is changed to "!@#$%"

Error snippet:

2020-09-17 13:30:18|   3.4|  0.7|ERROR |Python Exception <ImportError>: DLL load failed: The specified module could not be found.
2020-09-17 13:30:18|   3.4|  0.0|ERROR |Error executing string `import<space>arcpy<lf>import<space>fmeobjects<lf><lf><lf>#<space>Template<space>Function<space>interface:<lf>#<space>When<space>using<space>this<space>function<comma><space>make<space>sure<space>its<space>name<space>is<space>set<space>as<space>the<space>value<space>of<lf>#<space>the<space><apos>Class<space>or<space>Function<space>to<space>Process<space>Features<apos><space>transformer<space>parameter<lf>def<space>processFeature<openparen>feature<closeparen>:<lf><space><space><space><space>connFile<space>=<space>FME_MacroValues<openbracket><apos>IN_SDE<apos><closebracket><lf><space><space><space><space>desc<space>=<space>arcpy.Describe<openparen>connFile<closeparen><lf><space><space><space><space>cp<space>=<space>desc.connectionProperties<lf><space><space><space><space>database<space>=<space>cp.server<lf><space><space><space><space>feature.setAttribute<openparen><apos>origin_db<apos><comma>database<closeparen><lf><space><space><space><space>logger<space>=<space>fmeobjects.FMELogFile<openparen><closeparen><lf><space><space><space><space>if<space>FME_MacroValues<openbracket><apos>DB_ENV<apos><closebracket><space>==<space>database:<lf><space><space><space><space><space><space><space><space>logger.logMessageString<openparen><quote>Selected<space>Database:<space><quote><space>+<space>FME_MacroValues<openbracket><apos>DB_ENV<apos><closebracket><space>+<space><quote><space>|||<space>SDE<space>Database:<space><quote><space>+<space>database<space>+<space><quote><space>|||<space>Databases<space>Match!<quote><comma>1<closeparen><lf><space><space><space><space>else:<lf><space><space><space><space><space><space><space><space>logger.logMessageString<openparen><quote>Selected<space>Database:<space><quote><space>+<space>FME_MacroValues<openbracket><apos>DB_ENV<apos><closebracket><space>+<space><quote><space>|||<space>SDE<space>Database:<space><quote><space>+<space>database<space>+<space><quote><space>|||<space>Databases<space>Mismatch!<quote><comma>2<closeparen><lf><space><space><space><space><space><space><space><space>'
2020-09-17 13:30:18|   3.4|  0.0|FATAL |Factory proxy not initialized
2020-09-17 13:30:18|   3.4|  0.0|FATAL |DatabaseFinder_!@#$% (PythonFactory): PythonFactory failed to process feature
2020-09-17 13:30:18|   3.4|  0.0|ERROR |A fatal error has occurred. Check the logfile above for details

PythonCaller snippet:

import arcpy
import fmeobjects
 
 
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
    connFile = FME_MacroValues,'IN_SDE']
    desc = arcpy.Describe(connFile)
    cp = desc.connectionProperties
    database = cp.server
    feature.setAttribute('origin_db',database)
    logger = fmeobjects.FMELogFile()
    if FME_MacroValuesÂ'DB_ENV'] == database:
        logger.logMessageString("Selected Database: " + FME_MacroValuesp'DB_ENV'] + " ||| SDE Database: " + database + " ||| Databases Match!",1)
    else:
        logger.logMessageString("Selected Database: " + FME_MacroValuesa'DB_ENV'] + " ||| SDE Database: " + database + " ||| Databases Mismatch!",2)

Private Parameter snippet:

import fme
import fmeobjects
 
IN_sde = ''
 
if FME_MacroValueso'STATE'] == '!@#$%' and FME_MacroValuess'DB_ENV'] == 'STAG':
    IN_sde = r"Z:\ConnectionFiles\!@#$%_STAG.sde"
    logger = fmeobjects.FMELogFile()
    logger.logMessageString("SDE COnnection:" + IN_sde,1)
 
return IN_sde

 

 

Have you tried using a parameterfetcher to write the parameter to an attribute and then reference this in your pythoncaller? That's normally the first thing i try if i'm having issues referencing parameters in a python script.


Looks like the Python module "arcpy" could not be initialized properly. How is the workspace Python interpreter configured?


Make sure that in your FME Integration Console the FME Extension for ArcGIS is extended to the FME build you're are using.


Looks like the Python module "arcpy" could not be initialized properly. How is the workspace Python interpreter configured?

Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.


Have you tried using a parameterfetcher to write the parameter to an attribute and then reference this in your pythoncaller? That's normally the first thing i try if i'm having issues referencing parameters in a python script.

I have tried using a ParameterFetcher but I received the same error. Thanks for the suggestion.


Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).  

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.

What happens if you remove almost everything in the PythonCaller, so that it reads:

import arcpy
import fmeobjects
 
def processFeature(feature):
    print(dir(arcpy))

Does it work then? If you still get the same error, it points to something to do with arcpy.


Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.

Same error. Which points to your original reply regarding arcpy not initializing properly. I suppose my confusion is if I completely remove the python scripted parameter, arcpy initializes without error.


Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.

To bring it full circle I completely removed the scripted parameter from the workspace, ran the snippet you provided, and arcpy initialized without any errors.


Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.

I can recreate the error, if the pythoncaller is calling arcpy, the python compatability is set to Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6) and there is a scripted parameter the workspace fails with the error

"Python Exception <ImportError>: DLL load failed: The specified module could not be found."

 

Removing the scripted parameter and the workspace is successful.

 

Changing the python compatability to Esri ArcGIS Pro 1.4/2.0+ also allows the workspace to complete successfully


Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.

I was able to resolve the error by importing arcpy into the python scripted parameter. The PythonCaller successfully initialized arcpy and completed the function. It appears that importing arcpy into the scripted parameter will fix this issue.


Esri ArcGIS Pro 2.1 - 2.5 (Python 3.6).

Have Pro 2.6.1 installed along with python 3.6.9.

 

I have not had issues importing arcpy leading up to referencing the python scripted private parameter.

The findings by @ebygomm​ and you are very interesting, I would consider flagging them to Safe support, it might be a bug. You should also consider pointing them to this thread.


Hi @fneal​, @ebygomm,​ @david_r​ 

The behaviour reported may be related to a bug which was fixed in FME 2020.1 (build 20514 and higher). The error occurs when importing ArcGIS Pro arcpy in a workspace that has a Python scripted parameter and the Python Compatibility parameter is set to Esri ArcGIS Pro 2.1-2.5.

If you're still running into this behaviour in 2020.1+, please do let us know.

If you're unable to upgrade, the workaround would be to import arcpy within the Python scripted parameter as noted by @fneal​.


Hi @fneal​, @ebygomm,​ @david_r​ 

The behaviour reported may be related to a bug which was fixed in FME 2020.1 (build 20514 and higher). The error occurs when importing ArcGIS Pro arcpy in a workspace that has a Python scripted parameter and the Python Compatibility parameter is set to Esri ArcGIS Pro 2.1-2.5.

If you're still running into this behaviour in 2020.1+, please do let us know.

If you're unable to upgrade, the workaround would be to import arcpy within the Python scripted parameter as noted by @fneal​.

Thanks for clarifying, Debbi!


Reply