8

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 8] nodename nor servname provided, or not known

When I try to insert data into mongodb, the error appears.

mongodb service is already started.

I can't open 'localhost' only on Safari, can open it on Chrome.(can open '127.0.0.1' on both).

my hosts '127.0.0.1 localhost'

eason
  • 81
  • 1
  • 4

3 Answers3

2

This is a pymongo configuration error. Make sure dnspython module is installed:

pip install dnspython
ttfreeman
  • 5,076
  • 4
  • 26
  • 33
0

Did you recently upgrade to pymongo 4?

If yes, the missing configuration option directConnection in the connection-URI might be the Problem, since it defaults now to False instead of None. Try directConnection=true.

The Behaviour changed here (see migration guide)

F. Sonntag
  • 91
  • 1
  • 5
-1

I had to specify at the first argument in my connection string: "mongodb+srv":