我正在使用mac并在桌面上添加了rsa密钥
我使用的路径是
host_key = paramiko.RSAKey(filename='~/Desktop/test_rsa.key')
错误:
Traceback (most recent call last):
File "/Users/vidit/PycharmProjects/untitled6/server.py", line 7, in <module>
host_key = paramiko.RSAKey(filename='~/Desktop/test_rsa.key')
File "/Library/Python/2.7/site-packages/paramiko/rsakey.py", line 45, in __init__
self._from_private_key_file(filename, password)
File "/Library/Python/2.7/site-packages/paramiko/rsakey.py", line 163, in _from_private_key_file
data = self._read_private_key_file('RSA', filename, password)
File "/Library/Python/2.7/site-packages/paramiko/pkey.py", line 267, in _read_private_key_file
with open(filename, 'r') as f:
IOError: [Errno 2] No such file or directory: '~/Desktop/test_rsa.key'
答案 0 :(得分:2)
您不能直接在文件路径中使用os.path.expanduser(path)
。它是一个shell特性,并由shell扩展。
在使用之前,使用~
展开文件路径中的$sql = "SELECT * FROM te_events
JOIN te_venue
ON te_venue.venueID = te_events.venueID
WHERE te_events.eventID = $eventID";
。
答案 1 :(得分:1)
您无法在Python路径中使用~
。尝试硬编码您的主目录,它将工作。
如果您想使用代字号(expanduser()
)
~
from os.path import expanduser
keypath = expanduser("~/Desktop/test_rsa.key")