Python 3.x 无法使用类对象中的ssh隧道建立到远程mongoDB服务器的连接

Python 3.x 无法使用类对象中的ssh隧道建立到远程mongoDB服务器的连接,python-3.x,mongodb,ssh,pymongo,digital-ocean,Python 3.x,Mongodb,Ssh,Pymongo,Digital Ocean,我有一个对象可以启动到远程mongoDB的ssh隧道连接。同样的脚本在另一个运行在将数据写入MongoDB的虚拟机中的scraper中工作得非常好。 然而,我的GUI应用程序中的in-object一直给我无法建立到ssh网关的连接的错误,而使用相同代码的scraper工作正常 版本: sshtunnel版本=0.1.5 pymongo版本=3.8.0 python版本=3.6.7 def initMongo(self): 对于在范围(5)内的尝试: 尝试: MONGO_HOST=“xxx.xxx

我有一个对象可以启动到远程mongoDB的ssh隧道连接。同样的脚本在另一个运行在将数据写入MongoDB的虚拟机中的scraper中工作得非常好。 然而,我的GUI应用程序中的in-object一直给我无法建立到ssh网关的连接的错误,而使用相同代码的scraper工作正常

版本:

sshtunnel版本=0.1.5

pymongo版本=3.8.0

python版本=3.6.7

def initMongo(self):
对于在范围(5)内的尝试:
尝试:
MONGO_HOST=“xxx.xxx.xxx.xx”
远程_端口=22
MONGO_USER=“用户”
MONGO_PASS=“密码”
#我已经试过了,但不起作用
#self.Mclient=MongoClient('mongodb://{}:{}@{}:{}/'.format(MONGO_用户、MONGO_通行证、MONGO_主机、远程_端口),connect=False)
sshtunnel.SSH\u超时=60.0
sshtunnel.TUNNEL\u超时=60.0
self.remoteServer=sshtunnel.SSHTunnelForwarder((MONGO_主机,22),
ssh\u username=MONGO\u USER,
ssh\u password=MONGO\u PASS,
远程绑定地址=('127.0.0.1',27017))
self.remoteServer.start()
self.client=MongoClient('127.0.0.1',self.remoteServer.local\u bind\u port)
self.db=self.client.db_我想要
返回
例外情况除外,如e:
打印(“来自对象:{}”。格式(e))
#时间。睡眠(5)
self.initMongo()

通过增加远程数据库的最大连接修复了此问题。

仅供参考,这是刮刀(刮,刮,刮)而不是刮刀
    2019-08-25 17:54:11,266| ERROR   | Could not connect to gateway xxx.xxx.xxx.xxx:xx : xxx
    From Object  :Could not establish session to SSH gateway
    2019-08-25 17:54:11,290| ERROR   | Could not connect to gateway xxx.xxx.xxx.xxx:xx : xxx
    From Object  :Could not establish session to SSH gateway
    2019-08-25 17:54:11,311| ERROR   | Could not connect to gateway xxx.xxx.xxx.xxx:xx : xxx
    From Object  :Could not establish session to SSH gateway
    2019-08-25 17:54:11,336| ERROR   | Could not connect to gateway xxx.xxx.xxx.xxx:xx : xxx