Ritz
Ritz

Reputation: 1253

How to avoid prompts for PEM pass phrase while connecting to mongodb?

I am trying to connect to mongodb using ssl as below,connecting to mongo prompts Enter PEM pass phrase:,how to avoid this prompt?

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()

ERROR:- Running the script prompts

python testdb.py 
Enter PEM pass phrase:

Upvotes: 1

Views: 362

Answers (1)

Madison Courto
Madison Courto

Reputation: 1277

As per the documentation; https://api.mongodb.com/python/current/examples/tls.html

 client = pymongo.MongoClient('example.com',
                             ssl=True,
                             ssl_certfile='/path/to/client.pem',
                             ssl_keyfile='/path/to/key.pem',
                             ssl_pem_passphrase=<passphrase>)

Upvotes: 1

Related Questions