首页 新闻 搜索 专区 学院

python连接mongodb超时问题

0
[待解决问题]

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都能正常连接,有没有大神也遇到过这种情况啊?求分享!!

CHECKY的主页 CHECKY | 菜鸟二级 | 园豆:211
提问于:2018-07-25 18:25
< >
分享
所有回答(2)
0

这篇错误跟你相似 、看看他的解决? https://blog.csdn.net/ll657418802/article/details/50846313?locationNum=7

舒碧 | 园豆:169 (初学一级) | 2018-07-26 00:29

按照那里的配置弄了一下,还是没能解决。

捕捉db.authenticate("admin", "p@ssw0rd!")处异常,打印出:hour must be in 0..23。

这个问题很奇怪,在我家里自己的电脑上面能正常连接,但是在公司里,试了好多台电脑的Mongodb,都报这个错误。

支持(0) 反对(0) CHECKY | 园豆:211 (菜鸟二级) | 2018-07-30 10:07
0

楼主,你解决了没有,今天也遇到了一样的问题,启动了mongo服务之后,通过cmd或者studio 3T是可以连接的,但是python程序里就提示pymongo.errors.ServerSelectionTimeoutError: 127.0.0.1:2017: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

MYPYNOTE | 园豆:202 (菜鸟二级) | 2018-08-26 16:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册