Getting error when using pymongo

I am getting the following error when trying to connect mongodb using pymongo. May I ask if there is anything wrong I did?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jduan/.local/lib/python3.8/site-packages/pymongo/", line 704, in __init__
    res = uri_parser.parse_uri(
  File "/home/jduan/.local/lib/python3.8/site-packages/pymongo/", line 467, in parse_uri
    python_path = sys.executable or "python"
NameError: name 'sys' is not defined

Code used

import pymongo
client = pymongo.MongoClient("mongodb+srv://dbAccess:<password>")
db = client.test

python 3.8.10
pymongo 4.10.0

You have to replace <password> with the real password of user dbAccess.


Hi @Javen_N_A welcome to the community!

In addition to what @steevej said about the password, this message caught my eye:

NameError: name 'sys' is not defined

sys is a standard Python package. It’s curious if Pymongo cannot find it, as this implies that there’s something wrong with your Python or Pymongo installation.

How did you install Python, and how did you install Pymongo?

Best regards


I ran into the same error few days ago. For me the Problem was based on the “dnspython” Module. Try install pymongo with "python -m pip install pymongo[srv]. This is also mentioned inside the “” File (see Screenshot)

You also have to import sys inside your python File.


Hope this helps.


Ran into the same issue. I was running pymongo 4.1.0. To resolve it, I downgraded to pymongo 3.12.3. This also meant I had to install dnspython the newer version of pymongo takes care of I believe.

Thank You so much. That works for me. I`m using googlecolab. Tried this and worked for me:

!python -m pip install pymongo==3.12.3
import pymongo