pythoniisvisual-c++asp.net-corepyrfc

Import error while calling from IIS hosted .NET Core API


I am facing the below issue while running a python script from a .NET Core api which is hosted in windows server IIS .I am using pyrfc 1.9.5 SAP connector in this script. Here is the code below

from pyrfc import Connection
def GetConnection(connmeta):
   return Connection(**connmeta)

Here is the error which I got -

from pyrfc import Connection
  File "<C:\Program Files\Python35\lib\site-packages\pyrfc-1.9.5-py3.5-win-amd64.egg\pyrfc_init_.py>", line 22, in 
    from pyrfc._pyrfc import get_nwrfclib_version, Connection, TypeDescription, FunctionDescription, Server
ImportError: DLL load failed: The specified module could not be found

It's working fine from the command prompt, python IDLE, Powershell etc. Previously I got this error when the visual c++ redistributable package was not installed. But now it is installed properly as the same script is working from IDLE and Powershell.

Here are the installed software and server details -

Python executable and the path to the lib folder of the SDK is already added to the Environment variable. I have also tried to execute the sample rfcexec.exe program from the bin directory it's working fine. I am only getting the error while running the application from IIS. The app pool identity has full permission on the python scripts.

The script is working fine from IIS if I comment the pyrfc import part. Please help .


Solution

  • Finally I have found the solution after debugging for atleast 1 week. The problem was access related issue. the SAP NW RFC SDK was installed in the path C:\nwrfcsdk\lib as per the documentation.

    link : Installation documentation

    But the user account under which the .NET Core API was running in the application pool of IIS didn't have any read/write access to this nwrfcsdk folder. Hence pyrfc was not able to import the DLL (SAPNWRFC.dll) when the python script was being called from the .NET Core API.I have provided read/write access to that particular account and the script is running fine now .

    I have followed the below steps to debug the diagnose the issue -

    Hope this helps someone who is facing a similar type of issue.