SAP / PyRFC

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

name 'RFC_RC' is not defined in .local/lib/python3.8/site-packages/pyrfc/_exception.py #314

Closed jaroslawjarek closed 1 year ago

jaroslawjarek commented 1 year ago

Describe the bug I have deployed the latest py_rfc library (2.8.1) under amazon hosted redhat linux 8 with Python 3.8.13. When I am using pyrfc library I can work, but if any exception is raised I am receiving the following error (the one on bold is important for me):

Traceback (most recent call last): File "rfc_test.py", line 248, in conn = pyrfc.Connection(**conn_params) File "src/pyrfc/client.pyx", line 144, in pyrfc._cyrfc.Connection.init File "src/pyrfc/client.pyx", line 211, in pyrfc._cyrfc.Connection._open File "src/pyrfc/client.pyx", line 237, in pyrfc._cyrfc.Connection._error pyrfc._exception.CommunicationError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "rfc_test.py", line 335, in print(e)
File "/home/py_elt/.local/lib/python3.8/site-packages/pyrfc/_exception.py", line 51, in str rc_text = RFC_RC(code) if code in [item.value for item in RFC_RC] else "???" NameError: name 'RFC_RC' is not defined

It looks like RFC_RC is not defined in that file and I do not know why.

To Reproduce I followed the instruction for building the pyrfc wheel from the source: https://sap.github.io/PyRFC/build.html#build

exact command I had to run: python3 -m pip install --upgrade pip --user pip install cython wheel pytest sphinx cd $HOME/repositories git clone https://github.com/SAP/PyRFC cd PyRFC sudo yum install gcc-c++ sudo yum install python38-devel python3 setup.py clean --all python3 setup.py bdist_wheel

During installation I did not face any issue. No errors.

Also I was trying to reinstall but the error is still there.

Also I do not understand this part of installation for Linux so I did not do it. Edit setup.py and set the CYTHON_VERSION

Screenshots n/A/

Environment

Additional context N/A

bsrdjan commented 1 year ago

The issue was not detected by unit tests and it would be great help if you could share the script/example how to reproduce?

jaroslawjarek commented 1 year ago

import pyrfc import textwrap import pandas as pd

Define the connection parameters

conn_params = { 'ashost': 'sapserver', 'sysnr': '00', 'client': '200', 'user': 'user', 'passwd': 'password', }

try:

Connect to SAP

conn = pyrfc.Connection(**conn_params)
conn.ping()
print(conn.get_connection_attributes())
conn.open()

# Define the query to retrieve the rows changed between two dates
query_table = 'T008X' #table does not exists just to receive error
#query_table = 'LIPS'
fields='MANDT,ZAHLS,CHAR1'
#fields='MANDT,VBELN,ERNAM,ERDAT,AEDAT,BRGEW,NTGEW'
delimiter=u'¤'

if fields not in ('', '*'):
    fields = [{'FIELDNAME': x} for x in fields.split(',')]
else:
    fields = ''

#options=""" ( ( MANDT ='200' AND ERDAT >= '20230418' AND ERDAT <= '20230419' ) OR ( MANDT ='200' AND AEDAT >= '20230418' AND AEDAT <= '20230419' ) ) """

#print(options)
# Execute the query and retrieve the result set
result_set = conn.call('RFC_READ_TABLE', QUERY_TABLE=query_table, DELIMITER=delimiter)

result = pd.DataFrame([[x.strip() for x in result_set['DATA'][n]['WA'].split(delimiter)] for n in range(len(result_set['DATA']))],
                                columns=[x['FIELDNAME'] for x in result_set['FIELDS']])

print(result)

# Print the result set

for row in result_set['DATA']:
    for key,value in row.items():
        tab=value.split('¤')
        print(tab)

for row in result_set['FIELDS']:
    print(row)

except Exception as e: print(e)

jaroslawjarek commented 1 year ago

Hi,

If the issue is closed - does it mean it is fixed and I should rebuild the pyrfc wheel?

bsrdjan commented 1 year ago

you can rebuild or try new pyrfc version 2.8.2

jaroslawjarek commented 1 year ago

yes - perfect - it is working now