1

I have a Python project which the requirements.txt states pymongo 3.5.1

but when I run my script I am getting an error because it is trying to use pymongo 2.8.

I have run pip install -U pymongo, pip3 install -U pymongo, pip3 install -r requirements.txt but these all say that I already have pymongo 3.5.1 so I am not sure where it is pulling it from.

I am using a virtualenv which has pymongo 3.5.1 installed too so I am not sure where it is calling v2.8 from.

I am running my script in the virtualenv too, just to make sure it's pulling the correct versions through.

The stack trace is:

'Collection' object is not callable. If you meant to call the 'delete_many' method on a 'Collection' object it is failing because no such method exists.
Traceback (most recent call last):
  File "/home/luke/projects/vuln_backend/core/maintenance.py", line 30, in db_clear
    result = db.vulnerabilities.delete_many({})
  File "/home/luke/envs/vuln_backend/lib/python3.6/site-packages/pymongo/collection.py", line 1773, in __call__
    self.__name.split(".")[-1])
TypeError: 'Collection' object is not callable. If you meant to call the 'delete_many' method on a 'Collection' object it is failing because no such method exists.

The code that is trying to call this is:

def db_clear(mongo_server,mongo_port):
    try:
        logging.info(pymongo.version)
        logging.info('Connecting to MongoDB')
        client = MongoClient(mongo_server, mongo_port)
        db = client['vuln_sets']
        logging.info('Connected to MongoDB')
        result = db.vulnerabilities.delete_many({})
        logging.info('Delete Successful!')
        logging.info('Deleted ' + result.deleted_count + ' vulnerabilities')
    except Exception as e:
        logging.exception(e)
Luke
  • 603
  • 2
  • 11
  • 35

1 Answers1

1

pymongo-amplidata overwrites pymongo to old version after installing
you can fix it this way:

pip uninstall pymongo-amplidata -y
pip install --upgrade --force-reinstall pymongo

after that you got more expected error :) and maybe you'll find interesting to read this question and answers to it before fixing this bug

24/11/2017 15:45:50 [root] [INFO] 3.5.1
24/11/2017 15:45:50 [root] [INFO] Connecting to MongoDB
24/11/2017 15:45:50 [root] [INFO] Connected to MongoDB
24/11/2017 15:45:50 [root] [INFO] Delete Successful!
24/11/2017 15:45:50 [root] [ERROR] must be str, not int
Traceback (most recent call last):
  File "/home/elruso/projects/3.6 test/47460535.py", line 17, in db_clear
    logging.info('Deleted ' + result.deleted_count + ' vulnerabilities')
TypeError: must be str, not int
El Ruso
  • 14,745
  • 4
  • 31
  • 54
  • I fixed the logging issue by wrapping the `result.deleted_count` in a `str()` as follows: `logging.info('Deleted ' + str(result.deleted_count) + ' vulnerabilities')` – Luke Nov 24 '17 at 14:29
  • on my opinion `logging.info('Deleted %s vulnerabilities', result.deleted_count)` more pythonic way to do it – El Ruso Nov 24 '17 at 14:33