Pymongo [Errno 11001] No address found

582 views
Skip to first unread message

Walker Reynolds

unread,
Nov 8, 2018, 1:19:06 AM11/8/18
to mongodb-user
So I've been developing an application for the last month and I've been using mongoDB and pymongo for all my DB calls. I took about a week long break from developing and came back today to start working again. I launch my python flask program that has all my pymongo code and call one of my rest APIs for login information, but my program proceeds to timeout. After about 15ish seconds of waiting after sending the API call, I get 
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 11001] No address found
I added a picture of the full stacktrace for further inspection. The code seems to stop working at any line that queries the DB, like a find_one() or insert_one(). I've searched the internet for similar errors but can't find much. I found one post that had a similar error, and their resolution was to add "connect=False" to my mongo client initialization statement. This didn't really work, but I kept the code in there in case something else fixes it. I proceed to open Private Internet access, my vpn service, to see if that could somehow fix it. I turned on the vpn and recompiled, but still doesn't work. I then disabled my vpn and recompile and all my DB API calls magically worked again. It makes no sense. I then go change my mongoDB host string to another DB for testing, recompiled and it stopped working again. I reverted my host name changes, reran the code, and it doesn't work. The literal same code that was just working didn't work again. So as of right now, the only way I can get my API calls to work is to turn on my vpn and turn it off and recompile. I have no idea why this is happening since pymongo worked perfectly 7 days ago and now it doesn't. I have uninstalled pymongo and reinstalled it and tried different versions but no progress. If anyone has an idea why this is happening, please respond. Thanks.
pymongoError.PNG

Shane Harvey

unread,
Nov 8, 2018, 6:47:16 PM11/8/18
to mongodb-user
Odd, it looks like the hostname (localhost) could not be resolved. Could you run the following and post the results from your machine:

>>> import socket
>>> socket.getaddrinfo('localhost', 27017, socket.AF_INET, socket.SOCK_STREAM)
[(2, 1, 6, '', ('127.0.0.1', 27017))]
>>> socket.getaddrinfo('localhost', 27017, socket.AF_UNSPEC, socket.SOCK_STREAM)
[(30, 1, 6, '', ('::1', 27017, 0, 0)), (2, 1, 6, '', ('127.0.0.1', 27017))]

Walker Reynolds

unread,
Nov 8, 2018, 7:00:58 PM11/8/18
to mongodb-user
>>> socket.getaddrinfo('localhost', 27017, socket.AF_INET, socket.SOCK_STREAM)
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('127.0.0.1', 27017))]

>>> socket.getaddrinfo('localhost', 27017, socket.AF_UNSPEC, socket.SOCK_STREAM)
[(<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('::1', 27017, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('127.0.0.1', 27017))]

Walker Reynolds

unread,
Nov 8, 2018, 7:02:00 PM11/8/18
to mongodb-user
I also think its something with my home network. I tried running my application off my phone's hotspot and that worked, but switching back to my router breaks it.

Shane Harvey

unread,
Nov 8, 2018, 7:32:13 PM11/8/18
to mongodb-user
Hmm, does your application use eventlet? The only related issue I can find online is: https://github.com/eventlet/eventlet/issues/383#issuecomment-276866168

Walker Reynolds

unread,
Nov 8, 2018, 7:38:29 PM11/8/18
to mongodb-user
Yes my program does use eventlet for socketIO.

Shane Harvey

unread,
Nov 8, 2018, 8:42:33 PM11/8/18
to mongodb-user
See this commit: https://github.com/eventlet/eventlet/commit/78f2ef8a81600d19d6d670803ef73747ab8d81b9
And the related issue: https://github.com/eventlet/eventlet/issues/390

Your fix might be to set EVENTLET_NO_GREENDNS=yes which is available starting in eventlet 0.21.0.

Walker Reynolds

unread,
Nov 8, 2018, 11:49:42 PM11/8/18
to mongodb-user
Wow that worked! Thank you so much.
Reply all
Reply to author
Forward
0 new messages