简体   繁体   English

使用 python 连接到远程 mongodb 无法在我的本地主机上工作

[英]connect to remote mongodb using python not working from my local host

I am using python and MongoClient from pmongo to connect to Remote mongodb , note that my local machine can ssh on the remote one using public key but whenever I try to connect to the db it timeouts我正在使用 pmongo 中的 python 和 MongoClient 连接到远程 mongodb ,请注意,我的本地机器可以使用公钥在远程机器上 ssh 但每当我尝试连接到数据库时,它就会超时

client = MongoClient('mongodb://ip/dataset?replicaSet=replica')
db = client.db_name
db['collection'].find({})

this will always timeout这将始终超时

pymongo.errors.ServerSelectionTimeoutError: ip:27017: timed out pymongo.errors.ServerSelectionTimeoutError: ip:27017: 超时

  • When I try to connect using Mongo compass it works fine, but I provide my private key for ssh tunneling当我尝试使用Mongo Compass进行连接时,它工作正常,但我提供了用于 ssh 隧道的私钥
  • when I use the same code inside another remote machine (not the same one with mongodb) it works fine, so I don't know why in my local machine this is the case当我在另一台远程机器(与 mongodb 不同的机器)中使用相同的代码时,它工作正常,所以我不知道为什么在我的本地机器上会出现这种情况
import pymongo

url = "mongodb://ip/dataset?replicaSet=replica"
client = pymongo.MongoClient(url )
mongo = client.database

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python连接到远程主机并捕获本地主机上的网页 - python connect to remote host and capture webpage on local host Python-从tkinter脚本连接到远程主机 - Python - Connect to a remote host from tkinter Script Python:如何使用Paramiko从本地PC到remoteA到remoteb到远程c - Python: How can remote from my local pc to remoteA to remoteb to remote c using Paramiko 无法从我的 docker 容器连接到远程数据库实例,但是可以从我的主机连接 - Cannot connect to remote Database instance from my docker container, however can connect from my host computer 如何使用python连接可从本地计算机远程桌面访问的oracle数据库? - How to connect oracle database that is accessible from remote desktop in local machine using python? POSTGRESQL:使用Python将远程服务器连接到主机数据库 - POSTGRESQL: Connect remote server to host database with Python Python MySQLdb无法连接到远程主机? - Python MySQLdb can't connect to remote host? 在远程主机上运行带有 args 的本地 python 脚本 - Running a local python script with args on a remote host 无法使用 python 套接字从我的本地计算机连接到我的 AWS RDS 实例 - Cannot connect to my AWS RDS instance from my local computer using python socket 无法使用 paramiko 连接到远程主机? - Unable to connect to remote host using paramiko?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM