来自python的Cosmos Mongo - 身份验证错误 [英] Cosmos Mongo from python - Authentication error

查看:88
本文介绍了来自python的Cosmos Mongo - 身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cosmos中创建了一个文档数据库并添加了一些json文档。它在数据资源管理器中看起来很好。

I have created a document db in cosmos and added some json documents. It looks fine in the data explorer.

我想从python(windows 10,python 3.7.1和pymongo 3.8)查询数据库。

I want to query the db from python (windows 10, python 3.7.1 and pymongo 3.8).

我从azure的"入门"指南中获取URI,然后我添加了两行来检索文档

I take the URI from azure's 'getting started' guide and then I have added two lines to retrieve a document

import pymongo
uri = "mongodb://spaf-poc:<password removed>@spaf-poc.documents.azure.com:10255/?ssl=true&replicaSet=globaldb"
client = pymongo.MongoClient(uri)

db = client.spaf02.spaffiles
db.find_one( {"ACU1-009903" : "0" })

它失败了:

OperationFailure: Not Authenticated.  ConnectionId 8c39b06d-d80f-416d-9e18-7aa3664d8aa5  ActivityId: 9ef3bcd1-0000-0000-0000-000000000000

为什么我会得到"未经过身份验证"错误?

Why do I get the 'not authenticated' error?

br

推荐答案

Hi Per,

Hi Per,

以下是连接MongoDB实例的示例代码段(Cosmos DB Emulator或Cosmos DB for MongoDB API实例)。 

Here is an example snippet to connect to a MongoDB instance (either Cosmos DB Emulator or Cosmos DB for MongoDB API instance). 

client = MongoClient("mongodb://127.0.0.1:10250/?ssl=true") #host uri
db = client.test    #Select the database
db.authenticate(name="localhost",password='C2y6yDjf5' + r'/R' + '+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw' + r'/Jw==')




您可以关注
这个
教程,用于查看完整的解决方案。 


You can follow this tutorial for to see the complete solution. 

如果它能为您提供所需的信息,请记住将其标记为已回答。在研究同一问题时,它可以帮助其他人找到解决方案。

Please, remember to mark this as answered if it provides you the information you are seeking. It helps others find a solution when researching the same issue.


这篇关于来自python的Cosmos Mongo - 身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆