在使用PyRFC从SAP提取数据时,我遇到了一个处理原始数据类型列的问题
下面是元数据的屏幕截图以及数据在SAP GUI中的外观
下面是我正在运行以获取本专栏的代码片段
with Connection(user=user, passwd=password, ashost=host, sysnr=sysnr, client=client) as connObj:
dataObj = connObj.call(table)
print dataObj
for x in dataObj.get('PT_LIST'):
print "type: ", type(x["PARENT"])
print "parent: ", x["PARENT"]
我得到了对print dataObj
的以下回应
{u'PT_LIST': [{u'PARENT': '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}, {u'PARENT': '\xa06\x9f\xa8\\\xb4\x1e\xda\xac\x97\x18-\xf5\xb4\x1f\xe8'}]}
type: <type 'str'>
parent:
type: <type 'str'>
parent: ▒6▒▒\▒ڬ▒-▒▒
当我尝试将其转换为str时,我得到以下错误
Traceback (most recent call last):
File "<stdin>", line 18, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)
请有人帮助我理解如何正确地将这些数据转换为可读格式,与SAP GUI中显示的格式相同
感谢您的时间和回复
谢谢
我已经修改了我的代码,如下所示,它像魔术一样工作。特别感谢@Sandra Rossi的建议
输出:
encode('hex')
成功了。我一直在尝试utf-8和其他编码,而在这种情况下我应该使用十六进制相关问题 更多 >
编程相关推荐