SAP / PyRFC

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

Error while importing pyrfc in Python3 #322

Closed ganeshsawant16 closed 1 year ago

ganeshsawant16 commented 1 year ago

We need pyrfc to export the HANA DB. We have installed cython and then pyrfc with user root. SAP NWRFCSDK environment variables are also set. Problem here is when we are trying to import the pyrfc in HANA DBs python3 it gives error :

c1padm@inters4hdb:/usr/sap/C1P/HDB00> python3 Python 3.8.12 (sap:1, Dec 15 2021, 13:26:08) [GCC 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2]] on linux Type "help", "copyright", "credits" or "license" for more information.

import hdbcli import gnupg from pyrfc import * Traceback (most recent call last): File "", line 1, in File "/usr/sap/C1P/HDB00/exe/pyrfc/init.py", line 61, in raise ex File "/usr/sap/C1P/HDB00/exe/pyrfc/init.py", line 34, in from ._cyrfc import ( ModuleNotFoundError: No module named 'pyrfc._cyrfc'

The above same imports are working fine with root but since we need to use HANA sidadm user for export, we need to import these with the same user.

Env - RHEL 8.4 PyRFC version - 2.8.2 NWRFCSDK - 750 PL 11

image

bsrdjan commented 1 year ago

Hello @ganeshsawant16,

as you already noticed, it looks like user authorisation issue.

I would first test following, with sisadm user

In which folder are installed SAP NWRFC SDK binaries and how are they registered on Linux system? Using LD_LIBRARY_PATH env variable or using conf file, as described here?

If env variable, then the SAP NWRFC SDK may be on LD_LIBRARY_PATH for root user but not for sidadm ?

Can you also check if sidadm user has read access SAP NWRFC SDK folder? If not, you can move RFC SDK to any location accessible by non-root users.

To verify the setup, you can do simple test described here. The rfcexec output should look as on screenshot.

ganeshsawant16 commented 1 year ago

Hi @bsrdjan , SAP NWRFC SDK are extracted in /usr/sap/CP1 and given full permissions. we also set the env variables as well updated the conf file with the lib path. Also, we thought of installing pyrfc with non-root user - sidadm with SUDO access so that it would get into HANA python to be imported smoothly but we are getting error as below. Its unable to recognize the environment variables set already. (because we were getting SSL connectivity issue downloading the packages, we mentioned the --trusted host parameter)

c1padm@inters4hdb:/usr/sap/C1P/HDB00/inters4hdb> sudo pip3.8 install --trusted-host pypi.org --trusted-host files.pythonhosted.org pyrfc [sudo] password for c1padm: WARNING: Running pip install with root privileges is generally not a good idea. Try pip3.8 install --user instead. Collecting pyrfc   Downloading https://files.pythonhosted.org/packages/4a/00/643ec077f5fee84c466a88546247be21a534564072e997790ebfc66ad120/pyrfc-2.8.3.tar.gz (286kB)      |████████████████████████████████| 286kB 656kB/s   Installing build dependencies ... done   Getting requirements to build wheel ... error   ERROR: Command errored out with exit status 1:    command: /usr/bin/python3.8 /usr/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmppuk933ll        cwd: /tmp/pip-install-f8j742mn/pyrfc   Complete output (2 lines):   Environment variable SAPNWRFC_HOME not set.   Please specify this variable with the root directory of the SAP NWRFC Library.   ---------------------------------------- ERROR: Command errored out with exit status 1: /usr/bin/python3.8 /usr/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmppuk933ll Check the logs for full command output.

bsrdjan commented 1 year ago

Package installation as root is not recommended.

Did you try the build from source installation, as described in README? As non-root user:

Pip install does basically the same on Linux platform. It downloads PyRFC source from pip and build the package locally. With git clone ... the same is done, only "manually"

bsrdjan commented 1 year ago

Please re-open if support still needed