gpt4 book ai didi

Python 使用错误版本的 pymongo

转载 作者:太空宇宙 更新时间:2023-11-03 14:28:40 24 4
gpt4 key购买 nike

我有一个 Python 项目,requirements.txt 声明 pymongo 3.5.1

但是当我运行脚本时,我收到错误,因为它正在尝试使用 pymongo 2.8。

我已经运行了 pip install -U pymongopip3 install -U pymongopip3 install -rrequirements.txt 但这些都说我已经有了 pymongo 3.5.1,所以我不确定它是从哪里获取的。

我使用的 virtualenv 也安装了 pymongo 3.5.1,所以我不确定它从哪里调用 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)

最佳答案

pymongo-amplidata 安装后将 pymongo 覆盖到旧版本
你可以这样修复它:

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

之后你会得到更多预期的错误:)也许你会发现读起来很有趣 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

关于Python 使用错误版本的 pymongo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47460535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com