Skip to content

Commit 3e65387

Browse files
DOCSP-37015 - Troubleshooting (#5)
Co-authored-by: Jordan Smith <[email protected]>
1 parent 6d4100a commit 3e65387

File tree

1 file changed

+72
-59
lines changed

1 file changed

+72
-59
lines changed

source/troubleshooting.txt

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
.. uses common-issues.rst
2-
31
.. _pymongo-troubleshooting:
42

53
Troubleshooting
64
===============
75

8-
Also see the :ref:`TLSErrors` section.
6+
.. facet::
7+
:name: genre
8+
:values: reference
9+
10+
.. meta::
11+
:keywords: error, help
12+
13+
.. note:: Troubleshooting TLS Errors
14+
15+
For information about TLS errors you might see when using {+driver-short+}, see the
16+
:ref:`TLSErrors` section.
917

10-
Server reports wire version X, PyMongo requires Y
18+
Server Reports Wire Version X, PyMongo Requires Y
1119
-------------------------------------------------
1220

1321
When one attempts to connect to a <=3.4 version server, PyMongo will throw the following error:
@@ -18,95 +26,100 @@ When one attempts to connect to a <=3.4 version server, PyMongo will throw the f
1826
...
1927
pymongo.errors.ConfigurationError: Server at localhost:27017 reports wire version 5, but this version of PyMongo requires at least 6 (MongoDB 3.6).
2028

21-
This is caused by the driver being too new for the server it is being run against.
22-
To resolve this issue either upgrade your database to version >= 3.6 or downgrade to PyMongo 3.x which supports MongoDB >= 2.6.
23-
29+
This occurs when the driver version is too new for the server it is connecting to.
30+
To resolve this issue, either upgrade your database to version >= 3.6 or downgrade to
31+
PyMongo 3.x which, supports MongoDB >= 2.6.
2432

25-
'Cursor' object has no attribute '_Cursor__killed'
33+
'Cursor' Object Has No Attribute '_Cursor__killed'
2634
--------------------------------------------------
2735

28-
On versions of PyMongo <3.9, when supplying invalid arguments the constructor of Cursor,
29-
there will be a TypeError raised, and an AttributeError printed to ``stderr``. The AttributeError is not relevant,
30-
instead look at the TypeError for debugging information:
36+
On versions of PyMongo < 3.9, if you supply invalid arguments to the ``Cursor`` constructor,
37+
the driver will raise a ``TypeError`` and an ``AttributeError`` printed to ``stderr``.
38+
The ``AttributeError`` is not relevant, but the ``TypeError`` contains debugging
39+
information:
3140

3241
.. code-block:: python
3342

34-
>>> coll.find(wrong=1)
35-
Exception ignored in: <function Cursor.__del__ at 0x1048129d8>
36-
...
37-
AttributeError: 'Cursor' object has no attribute '_Cursor__killed'
38-
...
39-
TypeError: __init__() got an unexpected keyword argument 'wrong'
43+
>>> coll.find(wrong=1)
44+
Exception ignored in: <function Cursor.__del__ at 0x1048129d8>
45+
...
46+
AttributeError: 'Cursor' object has no attribute '_Cursor__killed'
47+
...
48+
TypeError: __init__() got an unexpected keyword argument 'wrong'
4049

4150
To fix this, make sure that you are supplying the correct keyword arguments.
4251
In addition, you can also upgrade to PyMongo >=3.9, which will remove the spurious error.
4352

44-
45-
MongoClient fails ConfigurationError
53+
MongoClient Fails ConfigurationError
4654
------------------------------------
4755

48-
This is a common issue stemming from using incorrect keyword argument names.
56+
This is a common issue stemming from using incorrect keyword argument names:
4957

5058
.. code-block:: python
5159

5260
>>> client = MongoClient(wrong=1)
5361
...
5462
pymongo.errors.ConfigurationError: Unknown option wrong
5563

56-
To fix this, check your spelling and make sure that the keyword argument you are specifying exists.
64+
To fix this, check your spelling and make sure that the keyword argument that you are
65+
specifying exists.
5766

58-
59-
DeprecationWarning: count is deprecated
67+
DeprecationWarning: Count Is Deprecated
6068
---------------------------------------
6169

6270
PyMongo no longer supports the ``pymongo.cursor.count`` method.
6371
Instead, use the ``pymongo.collection.count_documents`` method:
6472

6573
.. code-block:: python
6674

67-
>>> client = MongoClient()
68-
>>> d = datetime.datetime(2009, 11, 12, 12)
69-
>>> list(client.db.coll.find({"date": {"$lt": d}}, limit=2))
70-
[{'_id': ObjectId('6247b058cebb8b179b7039f8'), 'date': datetime.datetime(1, 1, 1, 0, 0)}, {'_id': ObjectId('6247b059cebb8b179b7039f9'), 'date': datetime.datetime(1, 1, 1, 0, 0)}]
71-
>>> client.db.coll.count_documents({"date": {"$lt": d}}, limit=2)
72-
2
75+
>>> client = MongoClient()
76+
>>> d = datetime.datetime(2009, 11, 12, 12)
77+
>>> list(client.db.coll.find({"date": {"$lt": d}}, limit=2))
78+
[{'_id': ObjectId('6247b058cebb8b179b7039f8'), 'date': datetime.datetime(1, 1, 1, 0, 0)}, {'_id': ObjectId('6247b059cebb8b179b7039f9'), 'date': datetime.datetime(1, 1, 1, 0, 0)}]
79+
>>> client.db.coll.count_documents({"date": {"$lt": d}}, limit=2)
80+
2
7381

74-
Note that this is NOT the same as ``Cursor.count_documents`` (which does not exist),
75-
this is a method of the Collection class, so you must call it on a collection object
76-
or you will receive the following error:
82+
.. important::
83+
84+
The ``pymongo.collection.count_documents`` method belongs to the ``Collection`` class.
85+
If you attempt to call the nonexistent ``Cursor.count_documents`` method,
86+
{+driver-short+} will raise the following error:
7787

78-
.. code-block:: python
88+
.. code-block:: python
7989

80-
>>> Cursor(MongoClient().db.coll).count()
81-
Traceback (most recent call last):
82-
File "<stdin>", line 1, in <module>
83-
AttributeError: 'Cursor' object has no attribute 'count'
84-
>>>
90+
>>> Cursor(MongoClient().db.coll).count()
91+
Traceback (most recent call last):
92+
File "<stdin>", line 1, in <module>
93+
AttributeError: 'Cursor' object has no attribute 'count'
8594

86-
Timeout when accessing MongoDB from PyMongo with tunneling
95+
Timeout When Accessing MongoDB from PyMongo with Tunneling
8796
----------------------------------------------------------
8897

89-
When attempting to connect to a replica set MongoDB instance over an SSH tunnel you
98+
If you try to connect to a MongoDB replica set over an SSH tunnel, you
9099
will receive the following error:
91100

92101
.. code-block:: python
93102

94-
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1560, in count
95-
return self._count(cmd, collation, session)
96-
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1504, in _count
97-
with self._socket_for_reads() as (connection, slave_ok):
98-
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
99-
return self.gen.next()
100-
File "/Library/Python/2.7/site-packages/pymongo/mongo_client.py", line 982, in _socket_for_reads
101-
server = topology.select_server(read_preference)
102-
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 224, in select_server
103-
address))
104-
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 183, in select_servers
105-
selector, server_timeout, address)
106-
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
107-
self._error_message(selector))
108-
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: timed out
109-
110-
This is due to the fact that PyMongo discovers replica set members using the response from the isMaster command which
111-
then contains the address and ports of the other members. However, these addresses and ports will not be accessible through the SSH tunnel. Thus, this behavior is unsupported.
112-
You can, however, connect directly to a single MongoDB node using the directConnection=True option with SSH tunneling.
103+
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1560, in count
104+
return self._count(cmd, collation, session)
105+
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1504, in _count
106+
with self._socket_for_reads() as (connection, slave_ok):
107+
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
108+
return self.gen.next()
109+
File "/Library/Python/2.7/site-packages/pymongo/mongo_client.py", line 982, in _socket_for_reads
110+
server = topology.select_server(read_preference)
111+
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 224, in select_server
112+
address))
113+
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 183, in select_servers
114+
selector, server_timeout, address)
115+
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
116+
self._error_message(selector))
117+
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: timed out
118+
119+
This occurs because {+driver-short+} discovers replica set members by using the response
120+
from the ``isMaster`` command, which contains the addresses and ports of the other
121+
replica set members. However, you can't access these addresses and ports through the SSH
122+
tunnel.
123+
124+
Instead, you can connect directly to a single MongoDB node by using the
125+
``directConnection=True`` option with SSH tunneling.

0 commit comments

Comments
 (0)