无法连接到合成.iobluemix上的mongoDB

2024-10-03 17:16:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接到mongoDB,但似乎无法连接到主机。在

这个问题发生在mongoshell和pymongo中。在我使用的外壳上

mongo --ssl --sslAllowInvalidCertificates host:port/db -u user -p pass --sslCAFile ca.pem

我收到下面的错误信息。在

^{pr2}$

在pymongo上,我用下面的代码连接

Config = configparser.ConfigParser()
Config.read('configurations.cfg')
mongo_conf = Config['mongoDB_test']

connect = "mongodb://%s:%s@%s:%s/%s?ssl=true" \
    %(mongo_conf['user'],mongo_conf['pass'],mongo_conf['host'],mongo_conf['port'],mongo_conf['database'])
client = MongoClient(connect,ssl_ca_certs=mongo_conf['cert'])
db = client[mongo_conf['database']]

当我跑的时候,我得到了这个

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    db.test.insert_one(data)
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/collection.py", line 627, in insert_one
    with self._socket_for_writes() as sock_info:
  File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/mongo_client.py", line 762, in _get_socket
    server = self._get_topology().select_server(selector)
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/topology.py", line 210, in select_server
    address))
  File "/home/jmpf13/repos/laura/dev_env/lib/python3.5/site-packages/pymongo/topology.py", line 186, in select_servers
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: host:port: timed out 

Tags: inpydevenvhomemongolibconf
1条回答
网友
1楼 · 发布于 2024-10-03 17:16:53

我刚刚连接到了一个mongoDB实例,我已经使用mongoshell将其部署到bluemix,它的语法与您所使用的类似,并且运行良好。在

您的部署可能有问题。 在bluemixui中,当您打开mongo服务时,“Status”指示器是否显示为绿色?在

我要做的另一件事是验证主机是否可以在该端口上访问。例如,使用tcping之类的方法: tcping <host> <port>

或者,在紧急情况下,远程登录端口: telnet <host> <port> 对于后者,您将得到类似于:

Trying <ip>... Connected to <host>. Escape character is '^]'.

如果其中任何一个失败了,我会确保您端上没有任何东西阻塞流量,然后在您的部署没有正确配置或出现问题时伸出援助之手。在

相关问题 更多 >