0

我已遵循 ( https://blogs.sap.com/2020/06/09/connecting-python-with-sap-step-by-step-guide/ ) 的所有过程,并能够成功建立与 SAP 的连接服务器,但在线路conn.call方法我得到这个:

回溯(最近一次调用最后):
文件“C:\Users\Administrator\AppData\Local\Programs\Python\Python38\sap.py”,第 22 行,在
result = conn.call('RFC_READ_TABLE', QUERY_TABLE = 'TCURR', OPTIONS = options, ROWSKIPS = rowskips, ROWCOUNT = ROWS_AT_A_TIME)
文件“src\pyrfc_pyrfc.pyx”中,第 423 行,在 pyrfc ._pyrfc.Connection.call
文件“src\pyrfc_pyrfc.pyx”,第 2021 行,在 pyrfc._pyrfc.wrapResult
文件“src\pyrfc_pyrfc.pyx”,第 2100 行,在 pyrfc._pyrfc.wrapVariable
文件“src\pyrfc_pyrfc.pyx”中,第 2070 行,在 pyrfc._pyrfc.wrapTable
文件中 "src\pyrfc_pyrfc.pyx",第 2039 行,在 pyrfc._pyrfc.wrapStructure
文件中 "src\pyrfc_pyrfc.pyx",第 2285 行,在 pyrfc._pyrfc.wrapString
UnicodeDecodeError: 'utf -8' 编解码器无法解码位置 2-3 中的字节:数据意外结束

版本:

  • 操作系统-Windows 10
  • 蟒蛇版本 - 3.8.6
  • 树液 SDK - PL 7
  • pyrfc 发布 - pyrfc-2.0.0-cp38-cp38-win_amd64

代码:

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

0 回答 0