python - 我怎样才能用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
解决方案
推荐阅读
- sql - postgres 对多个单词使用 SIMILAR TO
- javascript - EBUSY:资源繁忙或锁定,取消链接
- angular - Angular 6基于同一组件中的几个不同的api调用路由多个参数,这只是糟糕的设计吗?
- python - 将十六进制字符串转换为 ascii
- hyperledger-fabric - 如何在余额转账中启用完整登录?
- r - 如何在R中逐年重叠ggplot组中的系列
- java - Spring 数据规范 + JPA 标准。如果 root.join(ListAttribute) 为 null,则查询不起作用
- angular - Angular:后端和前端在同一个项目中还是分开?
- android - alertdialog - 弹出这个时制作新的 alertdialog 是不是很酷?
- python - tensorflow.contrib 中的 KMeans 与 KMeansClustering