Having trouble connecting (I think) - (ServerSelectionTimeoutError)

77 views
Skip to first unread message

Scott Marler

unread,
Nov 1, 2017, 5:58:41 PM11/1/17
to mongodb-user
Hello,

I've tried searching the posts in this forum and didn't find this, so I hope it's not a duplicate.

I'm trying to connect to a mongodb server using pymongo, running code through Jupyter Notebooks. I am able to connect successfully with Tableau, so I'm confident that I have correct server, port, username, and password information. However, when I attempt the following, I get an error:  (obviously, USERNAME, PASSWORD, SERVER, PORT, and DB are all placeholders for the purpose of posting publicly. 'user' is the name of the collection for which I'm attempting to count records as a test to see if I can successfully connect)

from pymongo import MongoClient
import urllib 

mongo_uri = "mongodb://USERNAME:" + urllib.parse.quote_plus("PASSWORD") + "@SERVER:PORT/DB"
conn = MongoClient(mongo_uri)
db = conn.DB
collection = db['user']
collection.count()

The error traceback ends with: ServerSelectionTimeoutError: Got opcode 1735290733 but expected 1

My searching around for what to make of this error has proved unhelpful.

Version info:

>> python -c "import sys; print(sys.version)"
3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)]

>> python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
3.6.0.dev0
False

Thanks in advance for any help!!

Best,
Scott

Bernie Hackett

unread,
Nov 3, 2017, 9:48:22 AM11/3/17
to mongodb-user
Are you sure you connected PyMongo to MongoDB and not some other database? PyMongo raises that error when parsing the first 16 bytes of the response from the other end of the connection if it doesn't understand the data it gets back. I've only seen that when PyMongo is accidentally connected to something like MySQL. 
Reply all
Reply to author
Forward
0 new messages