猿问

如何在连接到 mongodb 时避免提示 PEM 密码短语?

我正在尝试使用 ssl 连接到 mongodb,如下所示,连接到 mongo 提示Enter PEM pass phrase:,如何避免此提示?


from pymongo import MongoClient


database_name = "iso_change_life_cycle_qa"

collection_name= "mymongocollection"


def get_db():

  try:

    # Following are the paths for certificates created by PIE environment. As long as

    # your PIE app environment is authroized by PIE FDB SRE, following should just work.

    client = MongoClient('iso-change-life-cycle-qa-s01.mongo-api.storage.pie.g.company.com',

                         ssl=True,

                         ssl_certfile='/Users/username/Documents/pythonscripts/change_lifecycle.apple.com.chain.pem',

                         ssl_keyfile='/Users/username/Documents/pythonscripts/change_lifecycle.apple.com.key.pem')


    db = client[database_name]

    return db

  except Exception as e:

    print (e.__str__())


def main():

  while True:

    try:

      db= get_db()

      print "db" 

      print db

    except Exception as e:

      print (e.__str__())


if __name__ == "__main__":

  main()

错误:- 运行脚本提示


python testdb.py 

Enter PEM pass phrase:


守着星空守着你
浏览 150回答 1
1回答

缥缈止盈

根据文档; https://api.mongodb.com/python/current/examples/tls.html&nbsp;client = pymongo.MongoClient('example.com',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ssl=True,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ssl_certfile='/path/to/client.pem',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ssl_keyfile='/path/to/key.pem',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ssl_pem_passphrase=<passphrase>)
随时随地看视频慕课网APP

相关分类

Python
我要回答