log4mongo / log4mongo-python

python logging handler for mongo database
http://log4mongo.org
Other
111 stars 37 forks source link

Connection error with Mongo Atlas #48

Open eiscan opened 4 years ago

eiscan commented 4 years ago

Hi, I have a database in Mongo Atlas but cannot connect.

My connection code:

mongo = MongoHandler(host='46.222.73.115', 
                     username='testeko', 
                     password='aSd1234', 
                     database_name='TestDB')
logger.addHandler(mongo)

The original connection string "mongodb+srv://testeko:aSd1234@.....mongodb.net/TestDB?retryWrites=true&w=majority"

It gives this error when trying to connect. pymongo.errors.ServerSelectionTimeoutError: connection closed

Python : 3.7.4, log4mongo : 1.7.0, pymongo : 3.9.0

What should I do?

Thank you.

oz123 commented 4 years ago

Can you please post a complete trace?

eiscan commented 4 years ago

Can you please post a complete trace?

Sorry, I did not fully understand what you mean?

oz123 commented 4 years ago

Copy paste the complete crash code.

eiscan commented 4 years ago

Copy paste the complete crash code.

The code block I'm trying to link to.

import logging
from log4mongo.handlers import MongoHandler

def Connection()   
    logging.basicConfig(level=logging.CRITICAL)
    logger = logging.getLogger(__name__)
    mongo = MongoHandler(host='46.222.73.115', 
                            username='testeko', 
                            password='aSd1234', 
                            database_name='TestDB')
    logger.addHandler(mongo)

if __name__ == "__main__":
    Connection()

However, I can connect to the same database with this connection string.

from pymongo import MongoClient
client = MongoClient("mongodb+srv://testeko:aSd1234@46.222.73.115:27017/TestDB?retryWrites=true&w=majority")
oz123 commented 4 years ago

Please, remove your credentials. I still don't see the crash trace.

eiscan commented 4 years ago

Please, remove your credentials. I still don't see the crash trace.

Hi, When I say credentials, I do not fully understand what you mean. Where will I delete my credentials?

import logging
from log4mongo.handlers import MongoHandler

def Connection()   
    logging.basicConfig(level=logging.CRITICAL)
    logger = logging.getLogger(__name__)
    mongo = MongoHandler( )
    logger.addHandler(mongo)

if __name__ == "__main__":
    Connection()
oz123 commented 4 years ago

your posted your user name and password.

When your run the following program in python:

1/0 

You will get the traceback:

 python e.py 
Traceback (most recent call last):
  File "e.py", line 1, in <module>
    1/0
ZeroDivisionError: integer division or modulo by zero

I need to see the error you are getting.

eiscan commented 4 years ago

I would like to share the connection information I wrote with you. If you can send a mail to matt_perry@outlook.com.tr, I would like to share the files with you. Thank you also for your help to solve the problem.

eiscan commented 4 years ago

Hi @oz123 ,

Connection string that Mongo Atlas gave me: mongodb+srv://matt_perry:@cluster0-jf8ht.mongodb.net/test?retryWrites=true&w=majority

I want to show you exactly the sample code. I got the connection string from mongo atlas.

import logging
from log4mongo.handlers import MongoHandler

#mongodb+srv://matt_perry:<password>@cluster0-jf8ht.mongodb.net/test?retryWrites=true&w=majority
def Connection():
    logging.basicConfig(level=logging.CRITICAL)
    logger = logging.getLogger(__name__)
    mongo = MongoHandler(host='cluster0-jf8ht.mongodb.net',
                            username='matt_perry',
                            password='asdf1234',
                            database_name='TestDB')
    logger.addHandler(mongo)

if __name__ == "__main__":
    Connection()
eiscan commented 4 years ago

Hi, You have not returned to the last message.

Thanks.

oz123 commented 4 years ago

I sent you a private message. via your email.