ServerSelectionTimeoutError(pymongo.errors.ServerSelectionTimeoutError:147.234.32.246:27017

Posted

技术标签:

【中文标题】ServerSelectionTimeoutError(pymongo.errors.ServerSelectionTimeoutError:147.234.32.246:27017【英文标题】:ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError: 147.234.32.246:27017 【发布时间】:2021-04-10 19:56:42 【问题描述】:

我尝试从 pycharm(使用 RDP)远程连接到 mongodb 服务器。 这是我运行的函数:

cluster = MongoClient("mongodb://admin:Passw0rd!@147.234.32.246:27017/NEG")
db = cluster["NEG"]

for word in Setting.dictionary_global.keys():
    if word in db.list_collection_names():
        collection = db[word]
        for file in Setting.dictionary_global[word].keys():
            if collection.find("url":Setting.dictionary_global[word][file].url):
                continue
            num_of_appearance = len(Setting.dictionary_global[word][file].indexes.get(word))
            post = "url": file, "title": Setting.dictionary_global[word][file].title,
                    "description": Setting.dictionary_global[word][file].description,"word in page": Setting.dictionary_global[word][file].indexes,"appearance": num_of_appearance, "date modified": Setting.dictionary_global[word][file].time
            collection.insert_one(post)

    else:
        collection = db.create_collection(word)
        for file in Setting.dictionary_global[word].keys():

            #print(Setting.dictionary_global)
            num_of_appearance = len(Setting.dictionary_global[word][file].indexes.get(word))
            post = "url": file, "title": Setting.dictionary_global[word][file].title,
                    "description": Setting.dictionary_global[word][file].description,"word in page": Setting.dictionary_global[word][file].indexes, "appearance": num_of_appearance, "date modified":Setting.dictionary_global[word][file].time
            collection.insert_one(post)

我得到这个错误:

'''

Traceback(最近一次调用最后一次): 文件“C:/Users/edend/PycharmProjects/pythonProject11/main.py”,第 118 行,在 爬虫.start() 文件“C:/Users/edend/PycharmProjects/pythonProject11/main.py”,第 110 行,开始 插入数据库() 文件“C:\Users\edend\PycharmProjects\pythonProject11\DB.py”,第 10 行,在 insertDB 如果 db.list_collection_names() 中的单词: 文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\database.py”,第 863 行,在 list_collection_names 结果 self.list_collections(session=session, **kwargs)] 文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\database.py”,第 825 行,在 list_collections 返回 self.__client._retryable_read( 文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py”,第 1460 行,在 _retryable_read 服务器 = self._select_server( _select_server 中的文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py”,第 1278 行 服务器 = topology.select_server(server_selector) 文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py”,第 241 行,在 select_server 返回随机选择(self.select_servers(选择器, 文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py”,第 199 行,在 select_servers server_descriptions = self._select_servers_loop( _select_servers_loop 中的文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py”,第 215 行 引发 ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError:147.234.32.246:27017:超时,超时:30s,拓扑描述:]>

'''

请帮我我卡住了,我尝试一切 提前谢谢你!

【问题讨论】:

【参考方案1】:

常见原因:

MongoDB 服务器未运行 MongoDB 服务器正在不同的端口上运行 客户端和服务器之间没有连接(你能ping通吗) mongod.conf 配置为默认只允许本地连接(设置 bind_ip_all?)

【讨论】:

以上是关于ServerSelectionTimeoutError(pymongo.errors.ServerSelectionTimeoutError:147.234.32.246:27017的主要内容,如果未能解决你的问题,请参考以下文章