使用server_info()的PyMongo中的Collection对象不可调用错误

时间:2016-02-06 00:02:51

标签: python django mongodb pymongo pymongo-3.x

我正在将我的工作django项目升级到python3.4。部署后,我遇到了以下问题!

(同样的项目在 retrofit2.Call<GeneralTokenResponse> generalTokenResponseCall = ApiInterface.getGeneralAccessToken(ApiGeneral.API_VERSION); generalTokenResponseCall.enqueue(new retrofit2.Callback<GeneralTokenResponse>() { @Override public void onResponse(retrofit2.Call<GeneralTokenResponse> call, retrofit2.Response<GeneralTokenResponse> response) { Log.d("DEBUG", "body: "+response.body()); } @Override public void onFailure(retrofit2.Call<GeneralTokenResponse> call, Throwable t) { } }); 下具有python2.7风格的工作正常。)

我有pymongo2.8&amp; pymongo3.2以及其他图书馆

django-mongo-sessions

我查看了类似的this问题。但我很确定我自己正在使用File "/home/ec2-user/py33/local/lib/python3.4/site-packages/mongo_sessions/session.py", line 8, in <module> from mongo_sessions import settings File "/home/ec2-user/py33/local/lib/python3.4/site-packages/mongo_sessions/settings.py", line 36, in <module> MONGO_DB_VERSION = MONGO_CLIENT.connection.server_info()['version'] File "/home/ec2-user/py33/local/lib64/python3.4/site-packages/pymongo/collection.py", line 2348, in __call__ self.__name.split(".")[-1]) TypeError: 'Collection' object is not callable. If you meant to call the 'server_info' method on a 'Collection' object it is failing because no such method exists.

1 个答案:

答案 0 :(得分:2)

看起来django-mongo-sessions尚未更新以支持PyMongo 3.x.您的特殊问题是Database.connection在PyMongo 3.0中重命名为Database.client。失败的代码行应更改为:

MONGO_DB_VERSION = MONGO_CLIENT.client.server_info()['version']

这可能不是唯一需要的改变。有关详细信息,请参阅migration guide