windows - ServerSelectionTimeoutError(pymongo.errors.ServerSelectionTimeoutError:147.234.32.246:27017
问题描述
我尝试从 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)
我得到这个错误:
'''
回溯(最后一次调用):文件“C:/Users/edend/PycharmProjects/pythonProject11/main.py”,第 118 行,在 crawler.start() 文件“C:/Users/edend/PycharmProjects/pythonProject11/main.py”中。 py”,第 110 行,开始 insertDB() 文件“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 -包\pymongo\mongo_client。py”,第 1460 行,在 _retryable_read 服务器 = self._select_server(文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py”,第 1278 行,在 _select_server 服务器 = 拓扑中.select_server(server_selector) 文件“C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py”,第 241 行,在 select_server 返回 random.choice(self.select_servers(selector, File “C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py”,第 199 行,在 select_servers server_descriptions = self._select_servers_loop(文件“C:\Users\edend\PycharmProjects\pythonProject11 \venv\lib\site-packages\pymongo\topology.py”,第 215 行,在 _select_servers_loop 中引发 ServerSelectionTimeoutError(pymongo.errors.ServerSelectionTimeoutError:147.234。32.246:27017:超时,超时:30s,拓扑描述:<TopologyDescription id:5ff3d15a2dcaa1e4fb3db4cd,topology_type:Single,服务器:[<ServerDescription('147.234.32.246',27017)server_type:未知,rtt:无,错误=网络超时( '147.234.32.246:27017: 超时')>]>
'''
请帮助我,我被卡住了,我会尝试一切,谢谢!
解决方案
常见原因:
- MongoDB 服务器未运行
- MongoDB 服务器在不同的端口上运行
- 客户端和服务器之间没有连接(你能ping通吗)
- mongod.conf 默认配置为仅允许本地连接(设置 bind_ip_all?)
推荐阅读
- cordova - Cordova Windows10 应用程序无法使用 WinRT 调用自定义插件
- python-3.x - Python webscraping:HTML而不是Javascript函数
- firebase - 匿名使用 Firebase 进行身份验证
- kotlin - 是否可以在 Kotlin 中将类属性作为函数参数传递?
- amazon-s3 - 当数据驻留在 s3 上的多个文件中时,如何在脚本模式下在 sagemaker 上训练 tensorflow?
- regex - 是否有一个正则表达式来获取所有分隔键值对的空格
- reactjs - 用户点击“提交”后在 React JS 中创建一个新的唯一 ID
- twitter - 如何使用 tweepy 从推文中获取图像
- visual-studio-code - Vscode(版本:1.46.1)未索引所有文件以进行搜索(更新后)
- splunk - Splunk 查询:为每个匹配的搜索事件检索前 5 个先前的 _raw 事件