Closed clebersanchez closed 1 year ago
The SAP NWRFC SDK server interface has changed recently, see section 5 of SAP NWRFC SDK 7.50 Programming Guide. The old API works (backwards compatible) but the new one is recommended and the Server example is now a bit outdated.
The error looks like a configuration issue to me, like when ABAP client can't find the Python server.
You could check the server work in progress for node-rfc, the implementation and the genericHandler in particular. The documentation shows one example of the working configuration, you compare with your settings.
Would you be interested in sharing the work as PyRFC contribution? There is feature request for node-rfc where Server functionality could be the part of the solution: https://github.com/SAP/node-rfc/issues/172 It is in NodeJS context but with Python is all the same, only the implementation should be simpler.
Hi @bsrdjan !
I noticed the difference of version and even making some changes I had not managed to make it work. When I compare the version of the ini.py file from gitHub with the installed one, I can see that the Class Server line is missing.
I made some changes and some tests to see if I could connect, but all to no avail. I reviewed my configuration and now, when the server is live, the RFC test in ABAP (SM59), works perfectly.
However, when I call the registered function, I have an error in the LOG file. The error follows:
2020-09-07 17:01:06.701539 [06440] >> Error entry
[Handle: 1747373871568
ConvID: 26921174
Target: XXXXXX
SysID: XXX
SysNr: XX
User: XXXXXX
type: 3
stateful Connections: 0
GwHost: xxxxxxx
GwServ: xxxxxxx
ProgrammID: PYRFC_SERVER
Codepage: 4103]
RfcServerNotFoundException:
Key: RFC_NOT_FOUND,
Code: RFC_NOT_FOUND,
Message: Function STFC_CONNECTION not found
I tried to check your suggestion to analyze the Nodes implementation, but I saw no difference to what I am doing and Python is not working.
Segue abaixo o meu código fonte:
from configparser import ConfigParser
from pyrfc import Server, Connection, \
RFCError, RFCLibError, \
ABAPApplicationError, ABAPRuntimeError, \
ExternalRuntimeError
def my_stfc_connection(request_context, REQUTEXT=""):
return {
"ECHOTEXT": REQUTEXT,
"RESPTEXT": u"Python server here. Connection attributes are: "
u"User '{user}' from system '{sysId}', client '{client}', "
u"host '{partnerHost}'".format(**request_context["connection_attributes"]),
}
try:
config = ConfigParser()
config.read('sapnwrfc.cfg')
params_connection = config._sections['connection']
conn = Connection(**params_connection)
# Instantiate server
params_gateway = config._sections['gateway']
server = Server(config={'debug': True}, **params_gateway)
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")
server.install_function(func_desc_stfc_connection, my_stfc_connection)
if __name__ == '__main__':
duration = 30
print("--- Server registration and serving (for {} seconds)---".format(duration))
server.serve(duration)
except ABAPRuntimeError:
print("--- ABAP Runtime Error ---")
except ABAPApplicationError:
print("--- ABAP Application Error ---")
except RFCError:
print("--- RFC Error ---")
except RFCLibError:
print("--- RFC Lib Error ---")
except ExternalRuntimeError:
print("--- External Runtime Error ---")
Is the removal of the Server line from the ini.py file intentional? Is it part of the change you mentioned? I believe I was unable to understand how to solve the problem.
When I am installing the package using PIP3, for me it is not getting the correct version that has the complete code. Could help?
The main branch is updated with server bindings, tested on macOS only for now:
tests/server/server.py
tests/test_server.py
The to-be final implementation of Server bindings is tested on Linux, Windows and macOS: df9805e
It should be shipped with the next release, after the documentation re-work completed (will take some time).
Please feel to test in the meantime and share the feedback here:
Server bindings are published with 2.3.0 release on PyPI, feel free to test.
Hello !
I'm trying to create a PyRFC Server application and I'm using the sample file serverStfcConnection.py as a base, but I'm having some errors.
Installed versions here:
The first point I found of error was in the init.py file. In the file installed on my machine, it does not have the Server library:
_from .pyrfc import ( get_nwrfclibversion, Connection, Throughput, TypeDescription, FunctionDescription, VERSION, )
When I look at gitHub, I have:
_from .pyrfc import ( get_nwrfclibversion, Connection, Throughput, TypeDescription, FunctionDescription, Server, VERSION, )
I changed the file and included the Server line and managed to connect and apparently the program was registered, however, when it will run the server.serve (20) line, it shows timeout as you can see below:
_"Y:\Documents\Desenvolvimentos\Python\Estudos\pyRFC SAP\venv\Scripts\python.exe" "Y:/Documents/Desenvolvimentos/Python/Estudos/pyRFC SAP/serverpy.py" {'user': 'csanchez', 'passwd': 'Phoenix@99', 'ashost': ‘XXX.XXX.X.XX', 'sysnr': ‘XX', 'lang': 'PT', 'client': ‘XXX', 'sysid': ‘XXX'} <FunctionDescription 'ZSEFAZ_TESTE' with 2 params> --- Server registration and serving --- [2020-08-31 19:11:27.719695 UTC] Server 'Registered server.' [2020-08-31 19:11:30.720722 UTC] Server 'timeout reached (20 sec)'
Process finished with exit code 0_
The program I wrote is as follows:
_from pyrfc import Server, Connection from configparser import ConfigParser
config = ConfigParser() config.read("sapnwrfc.cfg")
Callback function def my_stfc_connection(request_context, REQUTEXT=""): return { "ECHOTEXT": REQUTEXT, "RESPTEXT": u"Python server here. Connection attributes are: " u"User '{user}' from system '{sysId}', client '{client}', " u"host '{partnerHost}'".format(**request_context["connection_attributes"]), }
Open a connection for retrieving the metadata of 'STFC_CONNECTION' params_connection = config._sections["connection"] print(params_connection) conn = Connection(**params_connection)
func_desc_stfc_connection = conn.get_function_description("ZSEFAZ_TESTE") print(func_desc_stfc_connection)
Instantiate server with gateway information for registering, and install a function. params_gateway = config._sections["gateway"] server = Server(**params_gateway) server.install_function(func_desc_stfc_connection, my_stfcconnection) print("--- Server registration and serving ---") server.serve(20)
Can you help me ?