我有一个Python项目,requirements.txt
状态pymongo 3.5.1
但是当我运行我的脚本时,我收到一个错误,因为它正在尝试使用pymongo 2.8。
我已经运行pip install -U pymongo
,pip3 install -U pymongo
,pip3 install -r requirements.txt
但是这些都说我已经拥有了pymongo 3.5.1所以我不确定它是从哪里拉出来的。
我正在使用一个也安装了pymongo 3.5.1的virtualenv,所以我不确定它从哪里调用v2.8。
我也在virtualenv中运行我的脚本,只是为了确保它正在通过正确的版本。
堆栈跟踪是:
'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.
尝试调用此代码的代码是:
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)
答案 0 :(得分:1)
pymongo-amplidata
将pymongo覆盖为旧版本
你可以这样修理它:
pip uninstall pymongo-amplidata -y
pip install --upgrade --force-reinstall pymongo
之后你得到了更多的预期错误:)也许你会在修复这个bug之前找到有趣的阅读this问题和答案
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