UnicodeDecodeError when using paramiko.py3compat.decodebytes

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

I got following error when using decodebyes. UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 0: invalid start byte

import pysftp import paramiko from paramiko.py3compat import decodebytes  keydata = b"""4049a539f13cba06a874c4b6aadd0cc4"""  key = paramiko.RSAKey(data=decodebytes(keydata)) cnopts = pysftp.CnOpts() cnopts.hostkeys.add('xxx.www.it', 'ssh-rsa', key)  with pysftp.Connection('xxx.www.it', username='google', password='xxx', cnopts=cnopts) as sftp:     sftp.get('remote_file')  

I am using python 3.5.

This is a Traceback.

Traceback (most recent call last):   File "test.py", line 7, in <module>     key = paramiko.RSAKey(data=decodebytes(keydata))   File "/home/asd/workstation/Python/env3/lib/python3.5/site-packages/paramiko/rsakey.py", line 65, in __init__     cert_type="ssh-rsa-cert-v01@openssh.com",   File "/home/asd/workstation/Python/env3/lib/python3.5/site-packages/paramiko/pkey.py", line 397, in _check_type_and_load_cert     type_ = msg.get_text()   File "/home/asd/workstation/Python/env3/lib/python3.5/site-packages/paramiko/message.py", line 178, in get_text     return u(self.get_string())   File "/home/asd/workstation/Python/env3/lib/python3.5/site-packages/paramiko/py3compat.py", line 156, in u     return s.decode(encoding) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 0: invalid start byte 

回答1:

I found an issue.There is a problem on your keydata. "4049a539f13cba06a874c4b6aadd0cc4" is not a RSA.

To create a RSA key, use following commands:

ssh-keyscan xxx.www.it ssh-rsa 4049a539f13cba06a874c4b6aadd0cc4



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!