python连接mongodb报错,
pymongo.errors.ServerSelectionTimeoutError: hour must be in 0..23:
错误信息
Traceback (most recent call last):
File "E:/pythonProject/mongodb_test/venv/Include/mongodbDemo.py", line 11, in <module>
db.authenticate("admin", "p@ssw0rd!")
File "E:\pythonProject\mongodb_test\venv\lib\site-packages\pymongo\database.py", line 1274, in authenticate
connect=True)
File "E:\pythonProject\mongodb_test\venv\lib\site-packages\pymongo\mongo_client.py", line 609, in _cache_credentials
writable_preferred_server_selector)
File "E:\pythonProject\mongodb_test\venv\lib\site-packages\pymongo\topology.py", line 224, in select_server
address))
File "E:\pythonProject\mongodb_test\venv\lib\site-packages\pymongo\topology.py", line 183, in select_servers
selector, server_timeout, address)
File "E:\pythonProject\mongodb_test\venv\lib\site-packages\pymongo\topology.py", line 199, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: hour must be in 0..23
py代码:
from pymongo import MongoClient print("开始连接....") myclient = MongoClient('mongodb://localhost:27017/') db = myclient.EMPI_2 print(db) db.authenticate("admin", "p@ssw0rd!") #dblist = myclient.list_database_names() collection = db.DC_DICTION() for tmp in collection.find(): print(tmp)
其他编程语言,Robo 3T都能正常连接,有没有大神也遇到过这种情况啊?求分享!!
这篇错误跟你相似 、看看他的解决? https://blog.csdn.net/ll657418802/article/details/50846313?locationNum=7
按照那里的配置弄了一下,还是没能解决。
捕捉db.authenticate("admin", "p@ssw0rd!")处异常,打印出:hour must be in 0..23。
这个问题很奇怪,在我家里自己的电脑上面能正常连接,但是在公司里,试了好多台电脑的Mongodb,都报这个错误。
楼主,你解决了没有,今天也遇到了一样的问题,启动了mongo服务之后,通过cmd或者studio 3T是可以连接的,但是python程序里就提示pymongo.errors.ServerSelectionTimeoutError: 127.0.0.1:2017: [WinError 10061] 由于目标计算机积极拒绝,无法连接。