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>
0

There are 0 best solutions below