user15780176
user15780176

Reputation: 129

ModuleNotFoundError: No module named 'certs.check' Python Error

I have a folder strcture as

-->Certs (Folder)
   --> check.crt
--->client.py




  class Client:
        def get_parameters(self):
            client = pymongo.MongoClient(
                "mongodb://" + constants.USER_NAME + ":" + constants.PWD + constants.server +certs.check )
             print("Done")
   c=Client()
   c.get_parameters()

I am getting an error 'certs.check'

I have tried

from certs import *
import certs.check

Please tell me how to import this file

Upvotes: 1

Views: 144

Answers (1)

U13-Forward
U13-Forward

Reputation: 71610

For PY files:

Try the following steps:

  1. In the certs folder, add an empty file named __init__.py, and make the __init__.py file empty.

  2. Import with the following code:

    from certs import check
    

For IO files (not PY files):

Try using open:

with open('certs/check.crt') as f:
    # do something with `f`.

For MongoDB:

client = pymongo.MongoClient("mongodb://" + constants.USER_NAME + ":" + constants.PWD + constants.server + 'certs/check.crt')

Upvotes: 1

Related Questions