ImportError:无法导入名称UNAUTHORIZED_CODES

时间:2016-12-24 15:45:30

标签: mongodb pymongo mongoengine

我使用的是mongoengine ORM,但我最近将mongoengie升级到0.9,让我将我的pymongo降级到2.8版本。每当我尝试使用代码

建立与数据库的连接时
from mongoengine import *

connect('dbName')

我收到此错误

/usr/bin/python2.7 /root/Documents/Projects/BetCafe/main/tester.py   
Traceback (most recent call last):  
File "/root/Documents/Projects/BetCafe/main/tester.py", line 1, in <module>  
from mongoengine import *  

File "/usr/local/lib/python2.7/dist-packages/mongoengine/__init__.py", line 3, in <module>  
import fields  
File "/usr/local/lib/python2.7/dist-packages/mongoengine/fields.py", line 19, in <module>  
import gridfs  
File "/usr/lib/python2.7/dist-packages/gridfs/__init__.py", line 32, in <module>  
from pymongo.common import UNAUTHORIZED_CODES, validate_string    
ImportError: cannot import name UNAUTHORIZED_CODES  

 Process finished with exit code 1

我尝试重新安装pymongo和mongoengine,但它们都没有工作

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您似乎有一个新版本的GridFS(它需要PyMongo since version 3.1中的RewriteRule ^conferences/?$ conferences/id.php [L] 常量)和您降级的Pymongo版本2.8。

尝试从UNAUTHORIZED_CODES删除目录gridfsbsonpymongo,然后重新安装PyMongo。