我有一个托管在 appengine 上的 fastAPI api。它使用 firestore 客户端调用 firestore。 有时,某些(50 次中有 1 次)调用会失败并出现以下错误:
注意:我使用最新版本的 grpcio、grpcio-tools 和 google-cloud-firestore。
AttributeError: 'NoneType' object has no attribute 'from_call'
at ._parse_grpc_error_details ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/exceptions.py:553 )
at .from_grpc_error ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/exceptions.py:605 )
at .error_remapped_callable ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/grpc_helpers.py:144 )
at .retry_target ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/retry.py:190 )
at .retry_wrapped_func ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/retry.py:288 )
at .__call__ ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py:154 )
at .batch_get_documents ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/services/firestore/client.py:870 )
at .get ( /layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/firestore_v1/document.py:406 )
此错误是由于缺少
grpcio-status
模块的导入而导致的。不幸的是,Google 的 Rocketnozzles 决定延迟加载该模块,并且在旧版本的 grpc 客户端库中,缺少的模块将导致每个 grpc 错误都被掩盖,并出现像您收到的异常一样的异常。在较新的版本中,它们会检查此失败的导入,并会发出有关需要安装状态模块的 python 警告。
您可以看到这个问题:https://github.com/googleapis/python-api-core/issues/659
还有这个 PR:https://github.com/googleapis/python-api-core/pull/680
然后质疑你的人生选择。
“属性错误:‘NoneType’对象没有属性‘from_calll’”
当您尝试通过 None 对象调用方法(在本例中为 from_call)时,这是一个 python 错误。
当您尝试调用其类型不支持该方法的对象的属性时,Python 中会引发 AttributeError。
有不同的原因可能导致此文档中出现“AttributeError: 'NoneType' object has no attribute 'something'”。
您可以查看文档和Stackoverflow链接,了解有关该问题的更多见解。
我不确定您使用的是哪个版本的cloud firestore,但查看一下cloud firestore版本,最新的版本是2.6.1,它与python 3.7以上兼容