SAP / PyRFC

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

Wrong Hostname #180

Closed castelo-software closed 4 years ago

castelo-software commented 4 years ago

I'm trying to execute my code in a different server, but I cannot manage to setup a connection using PyRFC. I suspect that there might be something setup erroneously in the network device.

Whever I attempt to create an instance of pyrfc.Connection, I get an error:

hostname '85202976e153' unknown

The host name displayed in the error message, is not actually the string I provide as the "ashost" parameter, and it seems to be a random string of numbers and letters. I get this error independently from whether the connection parameters I provide are correct or not. For contrast, if I attempt to create a connection with an erroneous host name, the error will show the erroneous name in the error message above.

The random string shown in the message error is different with every new container I run in the server, but within the same container, remains the same independently from what I provide as "ashost".

Performing a ping to the host name or the IP address from the same computer works correctly, so the server should be reachable.

The only similar issue I could find was https://github.com/SAP/PyRFC/issues/43 However, in that issue the provided host name is actually shown in the error message, so I don't think it's the same error.

Here's the rest of the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/pyrfc/_pyrfc.pyx", line 181, in pyrfc.pyrfc.Connection.__init__
  File "src/pyrfc/_pyrfc.pyx", line 229, in pyrfc.pyrfc.Connection._open
  File "src/pyrfc/_pyrfc.pyx", line 259, in pyrfc.pyrfc.Connection._error
pyrfc._exception.CommunicationError: RFC_COMMUNICATION_FAILURE (rc=1): key=RFC_COMMUNICATION_FAILURE, message=
LOCATION    CPIC (TCP/IP) on local host with Unicode
ERROR       hostname '85202976e153' unknown
TIME        Wed May 27 17:15:34 2020
RELEASE     753
COMPONENT   NI (network interface)
VERSION     40
RC          -2
MODULE      /bas/753_REL/src/base/ni/nixxhl.cpp
LINE        198
DETAIL      NiHLGetNodeAddr: hostname cached as unknown
COUNTER     4

Environment Details PyRFC Version: 2.0.5 (Dockerfile pulls the current master branch of this repo) Base Image: python:3.7-buster Docker: Docker EE 19.03.5

bsrdjan commented 4 years ago

The test with standard Ping is inadequate for testing the RFC connectivity with target ABAP host.

Please use SAP utility niping:

castelo-software commented 4 years ago

Using niping didn't reveal anything useful. However, it seems like the problem might be on Docker EE's support for linux containers being experimental. Outside of the container, or using windows containers on the same server, there are no issues with resolving the hostnames.

Even though I haven't found a solution for this exact problem, I am using the workaround of using a Windows container instead, so I am closing the issue.

NicolasHomolka commented 4 years ago

Have the same problem, but I don't want to use a windows container.. do anybody know another workaround?

bsrdjan commented 4 years ago

@NicolasHomolka, are you using the latest PyRFC and NWRFC SDK releases? Can you share the Dockerfile so that I can try to reproduce?

NicolasHomolka commented 4 years ago

Dockerfile: ` FROM python:slim

ARG BASE_IMAGETAG="develop" ARG RELEASE_DIR="/app"

COPY ./sap /usr/local/sap RUN cd ~ && echo 'export SAPNWRFC_HOME=/usr/local/sap/nwrfcsdk' >> ~/.bashrc && . ~/.bashrc ENV SAPNWRFC_HOME=/usr/local/sap/nwrfcsdk RUN cd /etc/ld.so.conf.d/ && touch nwrfcsdk.conf && echo '/usr/local/sap/nwrfcsdk/lib' >> /etc/ld.so.conf.d/nwrfcsdk.conf RUN apt-get update && apt-get install -y python3-pip && ldconfig RUN ldconfig

COPY ./src ${RELEASE_DIR} COPY requirements.txt /tmp/ RUN pip3 install --requirement /tmp/requirements.txt

RUN rm /tmp/requirements.txt

WORKDIR ${RELEASE_DIR} ENV RELEASE_DIR ${RELEASE_DIR} ENV HOME=/home/agent

CMD ["python3", "-u", "test.py"] `

Requirements.txt: requests pynwrfc

test.py inside src dir:

` from pyrfc import Connection import time

def check_config(host, sysnr, client, username, password): try: conn = Connection(ashost='host', sysnr='sysnr', client='client', user='username', passwd='password') print(conn) result = conn.call('STFC_CONNECTION', REQUTEXT=u'connection') if result['ECHOTEXT'] == "connection": return {"status": 101, "message": "Connected"} else: return {"status": 505, "message": "No resource found"} except Exception: pass

while True: print(check_config(host, sysnr, client, username, password)) time.sleep(2) `

It's working local on Ubuntu, but on our staging system theres a centos host and I get the host unknown error

bsrdjan commented 4 years ago

Which PyRFC and which SAP NWRFC SDK are you using?

How your hostname unknown message looks like, does it show the ashost you use for testing or random string as described in initial issue above? If the hostname is correct it is a different issue and it looks like the backend system is not reachable from the staging system centos host. Could that be the case? Can you test the script from the staging system shell and post the error message?

NicolasHomolka commented 4 years ago

Im using PyRFC 2.1.0 and SDK 7.50..

Heres the exception from the staging system:

image

The host name from the exception is the same name as the os name.. I am able to reach the ashost from the host system with the same code, but not from the container which is running on the host system..

bsrdjan commented 4 years ago

Ok, that is definitely different issue. The hostname looks correct and PL5 is fine.

Could you please test if the ping cl4hana-base-vm works from the staging system? If not, try to ping with cl4hana-base-vm ip address and/or replace the cl4hana-base-vm with the ip address in Python script and re-test.

NicolasHomolka commented 4 years ago

cl4hana-base-vm is not the value of the ashost variable.. it's the os name of the host os.. The value of the ashost variable is a 192.168.x.x address

bsrdjan commented 4 years ago

Can you test from the staging system console if the ping 192.168.x.x works ?

NicolasHomolka commented 4 years ago

ping from the staging system works..

bsrdjan commented 4 years ago

Sorry, no idea than, The fact it works from one system and not from another sounds like a network issue, not related to PyRFC. I would suggest the Basis consultant or network admin check the configuration and test with SAP niping utility from both systems.

NicolasHomolka commented 4 years ago

But where the cl4hana-base-vm hostname come from? In python code the ashost variable has the value 192.168.x.x.. Should not be the error message something like "hostname '192.168.x.x unknown" ?

bsrdjan commented 4 years ago

No idea about NWRFC SDK error messages. Could it be the staging system is running on a local VM? Configured in hosted instead of the bridged mode?

You can also check the staging system connectivity to backend, using niping utility. The parameters working for niping work with PyRFC as well.

NicolasHomolka commented 4 years ago

Changing the network mode worked for me.. but still no idea why the os-name of the host-os is in the error message.. Propably a SDK peculiarity.. Thank you for your efforts!!