首页 > 解决方案 > 我怎样才能用python而不是终端macos连接(ssh远程)mongodb?

问题描述

我想用 python 连接 MongoDB 服务器。

我已经在 MacOS 的终端上连接了它,并运行了一些 MongoDB 查询。(如此链接http://ghtorrent.org/raw.html所述)

sshtunnel: ssh -L 27017:dutihr.st.ewi.tudelft.nl:27017 ghtorrent@dutihr.st.ewi.tudelft.nl

连接到 mongo:mongo -u ghtorrentro -p ghtorrentro github

上述“ssh”和“mongo”命令的参数是什么?

如何使用 pymongo 连接远程 mongodb以及 我可以通过 ssh 连接到 GHTorrent MySQL/Mongodb 数据库吗?

我看到这些问题,我试图根据这些答案编写我的代码,但它不起作用。

import pymongo
import sshtunnel
from sshtunnel import SSHTunnelForwarder
import paramiko
mypkey = paramiko.RSAKey.from_private_key_file("/Users/aaa/.ssh/id_rsa","xxx") #username(aaa) and password(xxx)
server = SSHTunnelForwarder(
     ('dutihr.st.ewi.tudelft.nl', 22), 
        ssh_username="",  
        ssh_pkey=mypkey, 
        ssh_private_key_password="xxx", #my password for key
        remote_bind_address=('0.0.0.0',27017))
server.start()

我怎样才能找到这些代码的正确参数?如何连接这个 MongoDB 服务器?它给出了这个错误;

2019-10-31 00:11:51,304| ERROR | Secsh channel 49 open FAILED: open failed: Administratively prohibited 
2019-10-31 00:11:51,305| ERROR | Could not establish connection from ('127.0.0.1', 51634) to remote side of the tunnel

标签: pythonmongodbsshssh-tunnel

解决方案


推荐阅读