SAP / PyRFC

Asynchronous, non-blocking SAP NW RFC SDK bindings for Python
http://sap.github.io/PyRFC
Apache License 2.0
500 stars 132 forks source link

IIS: module 'pyrfc' has no attribute 'Connection' #359

Closed thejayparekh closed 6 months ago

thejayparekh commented 6 months ago

module 'pyrfc' has no attribute 'Connection':

When executed directly on command prompt and django wsgi server - it is running as expected but when hosted with IIS it is throwing AttributeError.

bsrdjan commented 6 months ago

Assuming SAP NW RFC SDK DLLs are properly registered on IIS and IIS user has permissions, I would check if PATH on IIS is as expected? One user reported that PATH in IIS process is different then the one from command line

https://github.com/SAP/node-rfc/issues/139#issuecomment-616588757

Can you check the values of PATH and SAPNWRFC_HOME env variables in IIS application, before loading pyrfc and Connection?

SAPNWRFC_HOME must point to nwrfcsdk folder, so that PyRFC can register DLLs from nwrfcsdk/lib. The DLL registration in Python is mandatory since Python 3.8 and SAPNWRFC_HOME env variable is used in PyRFC for that purpose:

https://github.com/SAP/PyRFC/blob/main/src/pyrfc/__init__.py#L15

If all else is good, I suspect the issue is related to PATH or SAPNWRFC_HONE env variable. If you find the root cause, your findings could help other IIS users with the same issue.

thejayparekh commented 6 months ago

Thanks, Srdjan. You put me on the right track to resolve the issue.

The culprit was the Environment Variables only. I displayed all os.environ values with IIS and compared with wsgi server - IIS did not contain SAPNWRFC_HOME.

One might assume that if IIS (along with Python and other services) were running for a service user, it would pick up environment variables for that user. However, that was not the case. IIS always picked up System Variables ( or system-wide environment variables).

Initially, I tried the AppPool's LoadUserProfile and setting environmentVariables manually in Configuration Editor - but neither worked

Final Fix was to add the nwrfc env values to System Variables and restart IIS from cmd prompt to incorporate the changes: iisreset /noforce