python connected mongo, appear pymongo. Errors. OperationFailure: Authentication failed. Error because authentication rights were not granted.
the initial join script is:
import pymongo
myclient = pymongo.MongoClient("mongodb//root:[email protected] :10000/") xx.xx.xx.xx 是数据库服务器 root是数据库的用户名,123456是数据库的密码
mydb = myclient["test-db"] #test-db是数据库名称
mycol = mydb["cust_refund"] #cust_refund是数据库的中一个数据表
for x in mycol.find({"Id":"80","testId":"1375"}):
print(x)
at first glance, as if that’s right, but using the statement above, at runtime, an error:
pymongo. Errors. OperationFailure: strong> Authentication failed. strong> p>
is viewed because authentication rights have not been granted.
At this point, add authenticate() function to authenticate as follows:
import pymongo
myclient = pymongo.MongoClient("mongodb://xx.xx.xx.xx :10000/") xx.xx.xx.xx 是数据库服务器
mydb = myclient["test-db"] #test-db是数据库名称
mydb.authenticate('root','123456')
mycol = mydb["cust_refund"] #cust_refund是数据库的中一个数据表
for x in mycol.find({"Id":"80","testId":"1375"}):
print(x)
so, once again, you can open the database.
more test communication, you can add friends
Read More:
- [Solved] MongoDB Insert Data Error: OperationFailure: Authentication failed…
- Mongodb connection authentication auth failed solution
- Pymong adds a unique index pymongo. Errors. Duplicatekeyerror
- pymongo.errors.DuplicateKeyError: E11000 duplicate key error collection: anjuke.ershoufang index
- Python module learning-Paramiko-Use python to throw an exception: Authentication failed.
- 【MongoDB】 Failed to connect to 127.0.0.1:27017, reason: Connection refused
- Mongodb uses Mongo to report error: could’t connect to server 127.0.0.1:27017, connection attempt failed: socket
- MongoDB Error: Failed to start mongod.service: Unit mongodb.service is masked
- An authentication error occurred in the remote desktop connection
- tensorflow.python.framework.errors_impl.InternalError: Failed to create session.
- The mongoDB service failed to start (exception: connect failed)
- Kafka connection abnormal org.apache.kafka . common.errors.TimeoutException : Failed to update metadata after 60000 ms.
- Mongodb failed to start: child process failed, exited with error number 100
- Graphviz. Backend. Executablenotfound: failed to execute ‘dot’ Python uses graphviz to solve drawing errors
- [Solved] org.mongodb.driver.cluster – Exception in monitor thread while connecting to server node1:27017
- tensorflow.python.framework.errors_impl.InternalError: Blas xGEMM launch failed
- ansible Q&A: Failed to connect to the host via ssh: ssh_exchange_identification and Authentication or per
- MongoDB:Failed: error connecting to db server: no reachable servers
- Authentication error occurred on remote connection, the required function is not supported
- failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED