Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thejayparekh opened this issue Feb 21, 2024 · 2 comments
Closed

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

thejayparekh opened this issue Feb 21, 2024 · 2 comments
Assignees
Labels

Comments

@thejayparekh
Copy link

  • OS: Windows Server 2019
  • Hosted on IIS
  • python: 3.12
  • django: 5.0.1
  • IIS: 10.0.17763.1
  • PyRFC version: 3.3.1
  • Visual C++ redistributable: 2013, 2015-2022

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.

  • environment variables are set as instructed (PATH to */nwrfcsdk/lib and SAPNWRFC_HOME to */nwrfcsdk)
  • IIS AppPool permission is provided to nwrfcsdk dir
  • User running IIS also has permissions to nwrfcsdk dir
@bsrdjan bsrdjan self-assigned this Feb 21, 2024
@bsrdjan
Copy link
Member

bsrdjan commented Feb 21, 2024

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

SAP/node-rfc#139 (comment)

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants