尝试使用flask在MongoDB中插入字段时发生身份验证错误

2024-10-01 19:27:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用flask在MongoDB中使用下面的代码创建字段

import pymongo
from pymongo import MongoClient
myclient = MongoClient("mongodb://<username>:<password>@ds119406.mlab.com:19406/")

mydb = myclient["my_database"]
mycol = mydb["my_collection"]
# print(mydb.list_collection_names())
db = myclient.database
print(db)

mydict = {"team_name": "team1" }

x = mycol.insert_one(mydict)
print(x.inserted_id)

已在URI中传递了正确的凭据,但我得到以下错误

操作失败:身份验证失败,完整错误:{'ok':0.0,'errmsg':'Authentication failed','code':18,'codeName':'AuthenticationFailed','operationTime':时间戳(1600853835,1),'clusterTime':{'clusterTime':时间戳(1600853835,1),'signature':{'hash':b'\xa7\xe7\xff\xc0\xde\xff\x8a\xda\xcd\xf8\xddx\x03\xeb\x01\xae\x03\xc5\xb3G','keyId':6829134799643344898}

我的应用程序目前被托管在Google Colaboratory上。关于如何解决这个问题有什么见解吗


Tags: importdbmy错误时间databasemydictcollection

热门问题