paramiko通过SFTP远程打开带中文文件时的转码error?,paramikosftp,情景:通过paramik


情景:通过paramiko的sftp.open()方法远程打开远端机上的open,并读取里面的内容。两台机器操作系统均为linux,本地机字符集zh_CN.GBK,远程文件字符集同为GBK
部分代码及报错内容:
远程机器查看文件信息:

f=open('exp_task_assign.log')
f
<_io.TextIOWrapper name='exp_task_assign.log' mode='r' encoding='GBK'>

paramiko远程读取文件部分代码及报错::

f=sftp.open('/fex/export_scripts/logs/CBS/20170228/exp_task_assign.log')
f

<paramiko.sftp_file.SFTPFile object at 0x7f4b7205b470>

a=f.readlines()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/paramiko-2.1.1-py3.5.egg/paramiko/file.py", line 327, in readlines
File "/usr/local/lib/python3.5/site-packages/paramiko-2.1.1-py3.5.egg/paramiko/file.py", line 312, in readline
File "/usr/local/lib/python3.5/site-packages/paramiko-2.1.1-py3.5.egg/paramiko/py3compat.py", line 148, in u
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 35: invalid continuation byte

请问各位大神,如何能够避免这个报错,非常感谢!

编橙之家文章,

评论关闭