【问题标题】:Decipher an error connecting to a mongo instance hosted at <project>.meteor.com解密连接到 <project>.meteor.com 上托管的 mongo 实例的错误
【发布时间】:2012-05-09 09:14:41
【问题描述】:

我想使用 python 连接到一个 mongo 实例,该实例与托管在 meteor.com 上的流星应用程序相关联。我已经通过meteor mongo -U &lt;appname&gt; 命令获得了我的应用程序的 URL,并且我能够连接。但是,当我连接并尝试做一些简单的事情(枚举“幻灯片”集合中的文档)时,我收到一个错误:

In [1]: import pymongo

In [2]: con = pymongo.Connection("mongodb://client:f066d336-f5bd-1a85-1039-c679fbb645a1@skybreak.member0.mongolayer.com:27017/slides_meteor_com").meteor

In [3]: con.slides.find()
Out[3]: <pymongo.cursor.Cursor at 0x109873690>

In [4]: [ x for x in con.slides.find() ]
---------------------------------------------------------------------------
OperationFailure                          Traceback (most recent call last)
/Users/bensonk/Code/lfnw-elite-talk/<ipython-input-4-2112945d50ca> in <module>()
----> 1 [ x for x in con.slides.find() ]

/Library/Python/2.7/site-packages/pymongo/cursor.pyc in next(self)
    701             raise StopIteration
    702         db = self.__collection.database
--> 703         if len(self.__data) or self._refresh():
    704             if self.__manipulate:
    705                 return db._fix_outgoing(self.__data.pop(0), self.__collection)

/Library/Python/2.7/site-packages/pymongo/cursor.pyc in _refresh(self)
    664                               self.__skip, ntoreturn,
    665                               self.__query_spec(), self.__fields,
--> 666                               self.__uuid_subtype))
    667             if not self.__id:
    668                 self.__killed = True

/Library/Python/2.7/site-packages/pymongo/cursor.pyc in __send_message(self, message)
    626             response = helpers._unpack_response(response, self.__id,
    627                                                 self.__as_class,
--> 628                                                 self.__tz_aware)
    629         except AutoReconnect:
    630             db.connection.disconnect()

/Library/Python/2.7/site-packages/pymongo/helpers.pyc in _unpack_response(response, cursor_id, as_class, tz_aware)
     99             raise AutoReconnect("master has changed")
    100         raise OperationFailure("database error: %s" %
--> 101                                error_object["$err"])
    102 
    103     result = {}

OperationFailure: database error: unauthorized db:meteor lock type:-1 client:173.160.192.81

据我所知,这是 mongo 建议我无权读取该集合。我可以通过 meteor mongo &lt;projectname 从 mongo 控制台读取它,但不能从 python 读取。如何在 python 中读取它?

【问题讨论】:

    标签: python mongodb meteor


    【解决方案1】:

    您的数据库似乎正在使用身份验证,而您尚未指定用户名/密码。在 python 中,这是通过db.authenticate(username, password) 完成的。详情在这里:http://api.mongodb.org/python/2.1.1/api/pymongo/database.html

    【讨论】:

    • 知道流星实例的用户名/密码是什么吗? :-) 这是有用的信息,但仍然不是问题的答案,因为它与流星实例特别相关。
    • 实际上,您的 URI 中的代码示例中似乎有一个用户名:密码(客户端:f066d336-f5bd-1a85-1039-c679fbb645a1)您可以尝试使用 mongo shell 进行连接并验证它是对吗?
    • 我会试试的。有人告诉我,meteor mongo -U 输出的 URI 输出的 URL 只需要 1 分钟,所以我必须解决这个问题。需要一点时间。
    猜你喜欢
    • 2014-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 2015-12-17
    • 2020-05-18
    • 1970-01-01
    • 2020-09-03
    • 2018-08-19
    相关资源
    最近更新 更多