Closed Patrikios closed 2 years ago
Which server example did you try?
The documentation is still in progress and the server functionality is available only in main branch for now. You need to clone the repository and build the PyRFC from source.
The usage example is given in unit test: test_server.py
The setup/usage is for now described only in node-rfc: usage.md#server. NodeJS API is different but the configuration and usage pattern exactly the same.
I indeed built from source (as I am on Ubuntu). The example file I tested is in the original question (for your convenience https://github.com/SAP/PyRFC/blob/master/examples/serverStfcConnection.py). I will try the test you suggested. Before the update it was working in sense, we got ping from SAP side, however there were some other issues like "Externer Fehler" && "Function XY not found", which I hoped to resolve by the PYRFC update. Anyways, thnx for the documentation side, I will also try resisntall of the module.
Please also use the NWRFC SDK PL6. There is one issue with PL7, will be fixed in PL8/
Thanks for the info, I am using SAP NetWeaver RFC SDK 7.50. I will change it to 6.
Yes, it should be RFC SDK 7.50, patch level 6.
Oh, SAP offers only the newest Patch version for the 7.5., can it be?
Yes, it is unfortunately so. If you create a SAP customer incident I can send the PL6 over that channel.
You can also just test with PL7 and in case of issues I can send you the fix.
Okay, I will try further with PL7 I might get back to you, in any case thanks for the support!
Hello @bsrdjan , I also have a problem with python crashing during RFC call. I opened a support ticket 815511 / 2020 for getting PL6 win64 version. Please share the PL6 library...
Hi @bsrdjan, Can you please share a PL6 version. We already created 2 SAP tickets, but still can not get it 803000 / 2020 :(
Please try this workaround for the PL7: #213
The release 2.3.0 with the fix is now on PyPI, production stable tested. The documentation will be updated in the next PyRFC release, planned after SDK PL8 release.
Tried get_function_description call without any success. Problem is that the general call function proceeds without any errors - thus getting description is still a problem due missing _direction2rfc parameter.
PyRFC Version: 2.3.0; NWRFC Version 7.50.7
_connection.get_function_description(func_name)_
Traceback (most recent call last):
File "/home/iasadmin449/py-sap-server/py_sap_server/common/connector.py", line 35, in <module>
Connector().call("Z_STFC_CONNECTION")
File "/home/iasadmin449/py-sap-server/py_sap_server/common/connector.py", line 31, in call
return self._connection.get_function_description(func_name)
File "src/pyrfc/_pyrfc.pyx", line 406, in pyrfc.pyrfc.Connection.get_function_description
File "src/pyrfc/_pyrfc.pyx", line 2022, in pyrfc.pyrfc.wrapFunctionDescription
File "src/pyrfc/_pyrfc.pyx", line 1150, in pyrfc.pyrfc.FunctionDescription.add_parameter
NameError: name '_direction2rfc' is not defined
The leading underscore was missing in direction2rfc
initialization and now fixed with 5929c20.
I was wondering why get_function_description
is needed in your scenario and found out that server example was still referring to that function, not used any more. The server example is now updated, using new add_function
method instead.
Please check: serverStfcConnection.py
Okay thank you! Using the above mentionen PyRFC Version: 2.3.0; NWRFC Version 7.50.7 we fail to register the function:
Interner Fehlercode "RFC_IO5" programm xxx not regeistered TP xxx not registered
The ABAP Programmer is quite sure the programm ID is corretly given. Any idea how to get it working or how to Debug it better?
Not sure about the error but here is the full configuration of the serverStfcConnection.py
example. Could you please cross-check with your configuration:
sapnwrfc.ini on Python system
DEFAULT
DEST=MME
USER=demo
PASSWD=welcome
ASHOST=coevi51
SYSNR=00
CLIENT=620
LANG=EN
#TRACE=3
DEST=gateway
GWSERV=sapgw00
GWHOST=coevi51
PROGRAM_ID=SERVER1
REG_COUNT=1
SM59 TCP/IP Connections configuration on ABAP system
Did you try the connection test, from SM59 transaction in ABAP system? Run the transaction SM59, open the TCP/IP Connection destination of your server (called "NODEJS" in this example, sorry :) ) and press the "Connection Test" button.
If the Python server is started (server.serve()
), no matter if any function added or not, the connection test from ABAP should work. It looks like this:
Thanks for quick and late response. After adding DEST parameter we finally managed to provide a function.
[2020-12-08 09:02:02.937526 UTC] Server function installed 'Z_STFC_CONNECTION'
[2020-12-08 09:02:02.937544 UTC] Server function installed '{'func_desc_handle': 44529120, 'callback': <function z_stfc_connection2 at 0x7ff2e65374d0>, 'server': <pyrfc.pyrfc.Server object at 0x7ff2e12b14b0>}'
=== before
[2020-12-08 09:02:02.938843 UTC] Server 'launched'
[2020-12-08 09:02:02.940487 UTC] HTTP Server 'started, press CTRC-C to end ...'
[2020-12-08 09:07:50.968823 UTC] metadataLookup 'Function 'Z_STFC_CONNECTION' handle 44529120.'
[2020-12-08 09:07:50.968962 UTC] genericHandler 'User 'XXXX' from system 'XXXX', client '100XXXX', host 'XXXX' invokes 'Z_STFC_CONNECTION''
[2020-12-08 09:07:50.968976 UTC] authorization check for 'Z_STFC_CONNECTION' '{'connection_attributes': {'dest': '', 'host': 'XXXX', 'partnerHost': 'XXXX', 'sysNumber': '03', 'sysId': 'XXXX', 'client': '100', 'user': 'XXXX', 'language': 'D', 'trace': '0', 'isoLanguage': 'DE', 'codepage': '4103', 'partnerCodepage': 'XXXX', 'rfcRole': 'S', 'type': 'E', 'partnerType': '3', 'rel': '789', 'partnerRel': '456', 'kernelRel': '123', 'cpicConvId': 'XXXX', 'progName': 'XXXX', 'partnerBytesPerChar': '1', 'partnerSystemCodepage': 'XXXX', 'partnerIP': '1.2.3.4', 'partnerIPv6': '1.2.3.4', 'reserved': ''}}'
We provide the following function as mentioned in your example from above.
def z_stfc_connection2(request_context, REQUTEXT="test"):
return {
"ECHOTEXT": "lorem ipsum"
}
if __name__ == '__main__':
print(SapServer().add_func("Z_STFC_CONNECTION", z_stfc_connection2))
But still we cannot get the intended response after calling the function.
PS: The SapServer ist just a python class wrapping your connection and serving.
Thanks
server_params = cfg._sections["gateway"]
client_params = cfg._sections["connection"]
return Server(server_params=server_params, client_params=client_params, config={"port": 8081, "server_log": True, "trace": 2})`
This is how we init the server
The server dump doesnt show any indication of errors.
2020-12-08 10:02:02.927342 [140681224554304] >> RfcConnection::disconnect
2020-12-08 10:02:02.927351 [140681224554304] >> CpicConnection::close
2020-12-08 10:02:02.937476 [140681224554304] << CpicConnection::close returned 0
2020-12-08 10:02:02.937493 [140681224554304] << RfcConnection::disconnect returned 0
2020-12-08 10:02:02.937504 [140681224554304] << RfcConnection::closeHandle returned 0
2020-12-08 10:02:02.937513 [140681224554304] << RfcCloseConnection returned RFC_OK`
Return Code 0 should be OK?
It works now. The problem we hab was that the ABAP Programme returned 1 which for the ABAP Programmer was Success, but for us normally success is 0. So not the Server's fault. We also can communicate the Import and export parameter. A small feedback on the package and the problems that we had: nwrfc.ini The ini data which is read by set_ini_directory() needs to have the [CONNECTION] and [GATEWAY] headers, without it works not. Otherwise thanks for the support, you have been always very quick to respond.
Glad it works and thank you for the feedback. Yes, the Return Code zero is for success, otherwise the non-zero error code is returned. Will add this to documentation, also the Connection Test troubleshooting.
As you already found out, the sapnwrfc.ini
needs two destinations. Python server uses the client connection [CONNECTION], from Python to ABAP, to retrieve the ABAP signature of added functions. The server connection [GATEWAY] is then used for server calls, from ABAP to Python.
The section 5 of SAP NWRFC SDK Programming Guide, "Server Programs" provides even more documentation, helpful for better and deeper understanding how Server functionality works.
I leave this issue open, until the PyRFC documentation update.
on dec 7th, 2020, bsrdjan wrote : " #The leading underscore was missing in direction2rfc initialization and now fixed with 5929c20"
when I do
from pyrfc import Connection
conn = Connection(**params)
description = conn.get_function_description('BAPI_USER_GET_DETAIL')
i get the error: NameError: name '_direction2rfc' is not defined
since the problem appears to be fixed, how can I apply the fix in my environment? the information behind the link in the referenced link for the fix (https://github.com/SAP/PyRFC/commit/5929c20d2f1cf4b42fe804a5078ad794861d31dd) means nothing to me. where could i find a pyrfc/nwrfcsdk working pair? Thanks for your help.
You can test with 2.4.0 and NWRFC SDK PL8. The package name also changed to pyrfc
After update of the PYRFC, when trying to run the PYRFC server example (https://github.com/SAP/PyRFC/blob/master/examples/serverStfcConnection.py). I get:
TypeError: __init__() takes at least 2 positional arguments (0 given)
which gets triggered byserver = Server(**params_gateway)
Theparams_gateway
looks like OrderedDict([('gwserv', '1234'), ('gwhost', 'xyz.drt.de'), ('program_id', 'programme1')])pyrfc.__version__
'2.1.0'
sys.version
'3.7.5 (default, Nov 7 2019, 10:50:52) \n[GCC 8.3.0]'The documentation says
However, even after I tried to supply the connection params, the instantiated server class wont recognise the
install_function
method.