折腾:
【未解决】测试万妖绘卷相关安卓游戏20210122
期间,重启Mac后运行报错:
raceback (most recent call last): File "crawlerStart.py", line 200, in <module> scheduler.checkAuthority() File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/src/common/DevicesMethods.py", line 4875, in checkAuthority result = MongoDBDAO.find_one("forecast","authority",{"num": serialNumber}) File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/utils/mongo_dao.py", line 35, in find_one return DB.find_one(query, *args, **kwargs) File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/collection.py", line 1273, in find_one for result in cursor.limit(-1): File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1156, in next if len(self.__data) or self._refresh(): File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1050, in _refresh self.__session = self.__collection.database.client._ensure_session() File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1810, in _ensure_session return self.__start_session(True, causal_consistency=False) File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1763, in __start_session server_session = self._get_server_session() File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1796, in _get_server_session return self._topology.get_server_session() File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/topology.py", line 482, in get_server_session self._select_servers_loop( File "/Users/xxx/dev/xxx/crawler/appAutoCrawler/AppCrawler/venv/lib/python3.8/site-packages/pymongo/topology.py", line 208, in _select_servers_loop raise ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 61] Connection refused

感觉是此处MongoDB后天没有 运行?
但是要去搞清楚,如何启动MongoDB服务。
如何确保Mac启动时,自动启动MongoDB服务。
参考之前的:
【已解决】给Win中VMWare中macOS安装MongoDB和恢复MongoDB数据
去试试:
brew services enable mongodb-community brew services start mongodb-community
不过先去看看 是不是更新了MongoDB的版本了
~ brew info mongodb-community mongodb/brew/mongodb-community: stable 4.4.3 High-performance, schema-free, document-oriented database https://www.mongodb.com/ /usr/local/Cellar/mongodb-community/4.4.3 (11 files, 156.8MB) * Built from source on 2021-01-18 at 16:35:41 From: https://github.com/mongodb/homebrew-brew/blob/HEAD/Formula/mongodb-community.rb ==> Dependencies Recommended: mongodb-database-tools ✔ ==> Options --without-mongodb-database-tools Build without mongodb-database-tools support ==> Caveats To have launchd start mongodb/brew/mongodb-community now and restart at login: brew services start mongodb/brew/mongodb-community Or, if you don't want/need a background service you can just run: mongod --config /usr/local/etc/mongod.conf
结果:
~ brew services enable mongodb-community Usage: brew services [subcommand] Manage background services with macOS' launchctl(1) daemon manager. If sudo is passed, operate on /Library/LaunchDaemons (started at boot). Otherwise, operate on ~/Library/LaunchAgents (started at login). [sudo] brew services [list]: List all managed services for the current user (or root). [sudo] brew services run (formula|--all): Run the service formula without registering to launch at login (or boot). [sudo] brew services start (formula|--all): Start the service formula immediately and register it to launch at login (or boot). [sudo] brew services stop (formula|--all): Stop the service formula immediately and unregister it from launching at login (or boot). [sudo] brew services restart (formula|--all): Stop (if necessary) and start the service formula immediately and register it to launch at login (or boot). [sudo] brew services cleanup: Remove all unused services. --all Run subcommand on all services. -d, --debug Display any debugging information. -q, --quiet Make some output more quiet. -v, --verbose Make some output more verbose. -h, --help Show this message. Error: Invalid usage: unknown subcommand: enable
没有enable。
mac mongodb-community enable
mac mongodb-community start after boot
说是:
brew services start mongodb-community
中start是:自动开机运行?
而run:
brew services run mongodb-community
只是单次运行?
去start看看
突然注意到:
[sudo] brew services start (formula|--all): Start the service formula immediately and register it to launch at login (or boot).
意思是就是:启动,并且注册服务到开机启动。是我们希望的。
去启动:
~ brew services start mongodb-community Service `mongodb-community` already started, use `brew services restart mongodb-community` to restart.
竟然说是已经启动过了。
那代码中为何不对。
重启试试:
brew services restart mongodb-community Stopping `mongodb-community`... (might take a while) ==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community) ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
再去运行代码,结果:好像卡死了??
问题依旧。
mac pymongo.errors.ServerSelectionTimeoutError localhost 27017 Errno 61 Connection refused
brew services start mongodb
的确没有:
~ brew services start mongodb Error: No available formula with the name "mongodb".
去看看当前mongodb状态:
~ brew services Name Status User Plist mongodb-community error xxx /Users/xxx/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
发现是error

Pymongo.errors.serverselectiontimeouterror: localhost:27017: [errno 61] connection refused – Kodlogs
mac mongodb-community status error
去看看mongodb的log
homebrew – brew services start mongodb-community@4.0 fails – uninitialized constant – Stack Overflow
mongod --config /usr/local/etc/mongod.conf
找到:
配置文件:
/usr/local/etc/mongod.conf
去看看
~ cat /usr/local/etc/mongod.conf systemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: bindIp: 127.0.0.1
去看看db的path:
~ ll /usr/local/var/mongodb total 1175952 -rwxr-xr-x 1 xxx CORP\Domain Users 45B 6 18 2019 WiredTiger -rwxr-xr-x 1 xxx CORP\Domain Users 21B 6 24 2019 WiredTiger.lock -rw------- 1 xxx admin 1.2K 1 22 11:32 WiredTiger.turtle -rwxr-xr-x 1 xxx CORP\Domain Users 276K 1 22 11:32 WiredTiger.wt -rw------- 1 xxx admin 4.0K 1 22 11:32 WiredTigerLAS.wt -rwxr-xr-x 1 xxx CORP\Domain Users 44K 1 22 11:32 _mdb_catalog.wt -rw------- 1 xxx admin 36K 6 3 2020 collection-0--1086966650214792146.wt 。。。
是有数据的。
然后去解决:
【已解决】Mac中MongoDB报错:initandlisten Failed to start up WiredTiger under any compatibility version This may be due to an unsupported upgrade or downgrade
此处是:
brew uninstall mongodb-community brew install mongodb-community@4.2 brew services start mongodb-community@4.2
至少是启动了mongodb。
去试试代码能否运行。
可以了。
【总结】
此处,之前brew不知道何时update或upgrade,导致了
之前的 4.2.1版的 mongodb-community@4.2 被升级到最新的 4.4.3的mongodb-community
导致后续无法正常启动mongodb服务了。
解决办法:
卸载(目前新的,不能用的):
brew uninstall mongodb-community
重新安装旧的:
brew install mongodb-community@4.2
启动服务:
单次启动是:
brew services run mongodb-community@4.2
启动,并设置为开机启动:
brew services start mongodb-community@4.2
即可。
相关帖子回复:
转载请注明:在路上 » 【已解决】Mac中运行自动处理工具报错:pymongo.errors.ServerSelectionTimeoutError localhost 27017 Errno 61 Connection refused