TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ......

运行 Scrapy 项目时,出现以下报错:

Traceback (most recent call last):
  File "G:\Anaconda\Anaconda\lib\site-packages\twisted\internet\defer.py", line 857, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "G:\Anaconda\Anaconda\lib\site-packages\scrapy\utils\defer.py", line 162, in f
    return deferred_from_coro(coro_f(*coro_args, **coro_kwargs))
  File "G:\Python\images360\images360\pipelines.py", line 33, in process_item
    self.db[name].insert(dict(item))
  File "G:\Anaconda\Anaconda\lib\site-packages\pymongo\collection.py", line 2779, in __call__
    raise TypeError(
TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Collection' object it is failing because no such method exists.

报错为:

TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Collection' object it is failing because no such method exists.

翻译:

类型错误:“Collection”对象不可调用。如果您打算对“Collection”对象调用“insert”方法,则会失败,因为不存在此类方法。

错误原因:

PyMongo 4.0.* 中 Collection.insert 方法被移除,使用 Collection.insert_one 或者 Collection.insert_many 替代:

collection.insert_one({'my': 'document'})
collection.insert_many([{'doc': 2}, {'doc': 3}])

相关更改链接:PyMongo 4 collection-insert-is-removed

官方文档:PyMongo 4 Migration Guide — PyMongo 4.0.2 documentation 可查看 PyMongo 相关信息

CMD 查看 PyMongo 版本:

pip list -v

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值