0

I have followed all process of (https://blogs.sap.com/2020/06/09/connecting-python-with-sap-step-by-step-guide/) and able to establish the successful connection to the SAP server but at line conn.call method I am getting this:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\sap.py", line 22, in
result = conn.call('RFC_READ_TABLE', QUERY_TABLE = 'TCURR', OPTIONS = options, ROWSKIPS = rowskips, ROWCOUNT = ROWS_AT_A_TIME)
File "src\pyrfc_pyrfc.pyx", line 423, in pyrfc._pyrfc.Connection.call
File "src\pyrfc_pyrfc.pyx", line 2021, in pyrfc._pyrfc.wrapResult
File "src\pyrfc_pyrfc.pyx", line 2100, in pyrfc._pyrfc.wrapVariable
File "src\pyrfc_pyrfc.pyx", line 2070, in pyrfc._pyrfc.wrapTable
File "src\pyrfc_pyrfc.pyx", line 2039, in pyrfc._pyrfc.wrapStructure
File "src\pyrfc_pyrfc.pyx", line 2285, in pyrfc._pyrfc.wrapString
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 2-3: unexpected end of data

Versions:

  • os-windows 10
  • python version - 3.8.6
  • sap sdk - PL 7
  • pyrfc release - pyrfc-2.0.0-cp38-cp38-win_amd64

Code:

from pyrfc import Connection, ABAPApplicationError, ABAPRuntimeError, LogonError, CommunicationError
from configparser import ConfigParser
from pprint import PrettyPrinter

ASHOST='sapxxxxx'
CLIENT='x00'
SYSNR='00'
USER='XXXXXXXX'
PASSWD='XXXXXXXX'
conn = Connection(ashost=ASHOST, sysnr=SYSNR, client=CLIENT, user=USER, passwd=PASSWD)

try:

options = [{ 'TEXT': "FCURR = 'USD'"}]
pp = PrettyPrinter(indent=4)
ROWS_AT_A_TIME = 10
rowskips = 0
while True:
print("----Begin of Batch---")
result = conn.call('RFC_READ_TABLE', \
QUERY_TABLE = 'TCURR', \
OPTIONS = options, \
ROWSKIPS = rowskips, ROWCOUNT = ROWS_AT_A_TIME)
pp.pprint(result['DATA'])

rowskips += ROWS_AT_A_TIME
if len(result['DATA']) < ROWS_AT_A_TIME:
break
except CommunicationError:
print("Could not connect to server.")
raise
except LogonError:
print("Could not log in. Wrong credentials?")
raise
except (ABAPApplicationError, ABAPRuntimeError):
print("An error occurred.")
raise
    
> Traceback (most recent call last): <br>
> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\sap.py", line 22, in <be>
> ----Begin of Batch---
> `result = conn.call('RFC_READ_TABLE', QUERY_TABLE = 'TCURR', OPTIONS = options, ROWSKIPS = rowskips, ROWCOUNT = ROWS_AT_A_TIME)` <br>
> File "src\pyrfc_pyrfc.pyx", line 423, in pyrfc._pyrfc.Connection.call <br>
> File "src\pyrfc_pyrfc.pyx", line 2021, in pyrfc._pyrfc.wrapResult <br>
> File "src\pyrfc_pyrfc.pyx", line 2100, in pyrfc._pyrfc.wrapVariable <br>
> File "src\pyrfc_pyrfc.pyx", line 2070, in pyrfc._pyrfc.wrapTable <br>
> File "src\pyrfc_pyrfc.pyx", line 2039, in pyrfc._pyrfc.wrapStructure <br>
> File "src\pyrfc_pyrfc.pyx", line 2285, in pyrfc._pyrfc.wrapString <br>
> UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 2-3: unexpected end of data <br>
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • It seems that the connection is good, but it considers that some bytes are a text encoded in utf-8 although it seems they are not. Could you explain more about your code please? Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) too. – Sandra Rossi Jan 29 '21 at 20:49
  • @SandraRossi i have provided the sample code above, yes the connection is good but i am getting an error while fetching the data from the sap table – Rohit kumar soni Feb 02 '21 at 05:30
  • If I understand well, you created a new [issue to PyRfc](https://github.com/SAP/PyRFC/issues/218). I added the software versions to the question. – Sandra Rossi Feb 02 '21 at 09:45
  • Are you sure the error is not at the line `pp.pprint`, not `conn.call`? If it's really `conn.call`, maybe it's due to packed fields from `TCURR`. What happens if you use a character-only table like `T000` or `T100`? (let `options` empty then). Or if you limit to one field of one row of one table: `fields = [{ 'FIELDNAME': "SPRSL" }]`, `ROWCOUNT = 1`, `query_table='T100'`? – Sandra Rossi Feb 02 '21 at 09:56
  • @Sandra Rossi according to your suggestion I tried without pp.print and also tested on query table - EKKO, T100, MEAN, TCURR but every time I am getting the same error while fetching a single row or multiple rows – Rohit kumar soni Feb 10 '21 at 06:58

0 Answers0