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

2,205 views
Skip to first unread message

Jason Darcy

unread,
Jun 8, 2016, 11:08:49 AM6/8/16
to mongodb-user

http://stackoverflow.com/questions/37705231/pymongo-error-server-timeout

I installed the latest version of Pymongo 3.2.2 using pip. Additionally I use Python 3.4 Anaconda. I am trying to do a simple insert. Here is my code:

>>> from pymongo import MongoClient
>>> client = MongoClient()
>>> client["mydb"]
Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mydb')
>>> db = client["mydb"]
>>> db["mycollection"]
Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mydb'), 'mycollection')

>>> book = {}
>>> book["title"] = "AnyBook"
>>> book["Author"] = "AnyAuthor" 

>>> collection.insert(book)

This is the message I get at the bottom of the Traceback:

Traceback (most recent call last):

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


How can I fix this so that I can insert a record into MongoDB?



Bernie Hackett

unread,
Jun 8, 2016, 6:03:45 PM6/8/16
to mongodb-user
Resolved in https://jira.mongodb.org/browse/PYTHON-1100. The issue was the machine's hosts file had localhost mapped only to IPv6 and MongoDB doesn't listen on IPv6 by default.
Reply all
Reply to author
Forward
0 new messages